From 8a424a0a462f85be6c1f1de749fe9393ed8fa250 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Fri, 16 Jun 2023 01:13:03 +0800 Subject: [PATCH] Improve based on PR feedback --- .../core-server/src/utils/summarizeIndex.ts | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/code/lib/core-server/src/utils/summarizeIndex.ts b/code/lib/core-server/src/utils/summarizeIndex.ts index 2921ca6c18b1..091038cdaccf 100644 --- a/code/lib/core-server/src/utils/summarizeIndex.ts +++ b/code/lib/core-server/src/utils/summarizeIndex.ts @@ -6,14 +6,13 @@ const PAGE_REGEX = /(page|screen)/i; export const isPageStory = (storyId: string) => PAGE_REGEX.test(storyId); -const isOnboardingEntry = (entry: IndexEntry) => ['example-button--warning'].includes(entry.id); - /** - * Filter out example stories that are generated by the CLI + * Is this story generated by the CLI */ -const isExampleEntry = (entry: IndexEntry) => +const isCLIExampleEntry = (entry: IndexEntry) => [ 'example-introduction--docs', + 'configure-your-project--docs', 'example-button--docs', 'example-button--primary', 'example-button--secondary', @@ -26,6 +25,15 @@ const isExampleEntry = (entry: IndexEntry) => 'example-page--logged-out', ].includes(entry.id); +/** + * Is this story part of the CLI generated examples, + * including user-created stories in those files + */ +const isAnyExampleEntry = (entry: IndexEntry) => + entry.id.startsWith('example-button--') || + entry.id.startsWith('example-header--') || + entry.id.startsWith('example-page--'); + export function summarizeIndex(storyIndex: StoryIndex) { let storyCount = 0; const componentTitles = new Set(); @@ -39,10 +47,10 @@ export function summarizeIndex(storyIndex: StoryIndex) { let storiesMdxCount = 0; let mdxCount = 0; Object.values(storyIndex.entries).forEach((entry) => { - if (isExampleEntry(entry)) { + if (isCLIExampleEntry(entry)) { if (entry.type === 'story') exampleStoryCount += 1; if (entry.type === 'docs') exampleDocsCount += 1; - } else if (isOnboardingEntry(entry)) { + } else if (isAnyExampleEntry(entry)) { if (entry.type === 'story') onboardingStoryCount += 1; if (entry.type === 'docs') onboardingDocsCount += 1; } else if (entry.type === 'story') {