mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-18 05:02:24 +08:00
Refactored page title splitting and space insertion
This commit is contained in:
parent
301aac6ccc
commit
056e20ad75
@ -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';
|
||||
|
Loading…
x
Reference in New Issue
Block a user