Refactored page title splitting and space insertion

This commit is contained in:
César Souza Liedke 2020-09-25 15:12:37 -03:00
parent 301aac6ccc
commit 056e20ad75

View File

@ -7,12 +7,7 @@ import { Preview } from '../components/preview/preview';
export type Item = StoriesHash[keyof StoriesHash];
const nonAlphanumSpace = /[^a-z0-9 ]/gi;
const doubleSpace = /\s\s/gi;
const replacer = (match: string) => ` ${match} `;
const addExtraWhiteSpace = (input: string) =>
input.replace(nonAlphanumSpace, replacer).replace(doubleSpace, ' ');
const splitTitleAddExtraSpace = (input: string) => input.split('/').join(' / ');
const getDescription = (item: Item) => {
if (isRoot(item)) {
@ -23,7 +18,7 @@ const getDescription = (item: Item) => {
}
if (isStory(item)) {
const { kind, name } = item;
return kind && name ? addExtraWhiteSpace(`${kind} - ${name} ⋅ Storybook`) : 'Storybook';
return kind && name ? splitTitleAddExtraSpace(`${kind} - ${name} ⋅ Storybook`) : 'Storybook';
}
return 'Storybook';