diff --git a/apps/frontpage/app/docs-all/sitemap.ts b/apps/frontpage/app/docs-all/sitemap.ts index 33ea1df6..cc08c7c0 100644 --- a/apps/frontpage/app/docs-all/sitemap.ts +++ b/apps/frontpage/app/docs-all/sitemap.ts @@ -1,5 +1,5 @@ import { MetadataRoute } from 'next'; -import { generateDocsTree } from '../../lib/get-tree'; +import { getDocsTreeFromPath } from '../../lib/get-docs-tree-from-path'; import { docsVersions } from '@repo/utils'; import { FlatTreeNode, @@ -12,7 +12,7 @@ export default function sitemap(): MetadataRoute.Sitemap { const listofTrees = docsVersions.map((version) => { return { version: version, - tree: generateDocsTree(`content/docs/${version.id}`), + tree: getDocsTreeFromPath(`content/docs/${version.id}`), }; }); diff --git a/apps/frontpage/app/docs/[[...slug]]/page.tsx b/apps/frontpage/app/docs/[[...slug]]/page.tsx index b991457f..03f0d903 100644 --- a/apps/frontpage/app/docs/[[...slug]]/page.tsx +++ b/apps/frontpage/app/docs/[[...slug]]/page.tsx @@ -1,12 +1,12 @@ import { notFound, redirect } from 'next/navigation'; import Link from 'next/link'; import type { TreeProps } from '@repo/utils'; -import { GLOBAL_SEARCH_META_KEYS, GLOBAL_SEARCH_IMPORTANCE } from '@repo/ui'; +import { globalSearchMetaKeys, globalSearchImportance } from '@repo/ui'; import { latestVersion, cn } from '@repo/utils'; import { getVersion } from '../../../lib/get-version'; import { getPageData } from '../../../lib/get-page'; import { Renderers } from '../../../components/docs/renderers'; -import { generateDocsTree } from '../../../lib/get-tree'; +import { getDocsTreeFromPath } from '../../../lib/get-docs-tree-from-path'; import { DocsFooter } from '../../../components/docs/footer/footer'; import { Metadata } from 'next'; import { TableOfContent } from '../../../components/docs/table-of-content'; @@ -27,8 +27,8 @@ export async function generateMetadata({ description: "Storybook is a frontend workshop for building UI components and pages in isolation. Thousands of teams use it for UI development, testing, and documentation. It's open source and free.", other: { - [GLOBAL_SEARCH_META_KEYS.VERSION]: activeVersion.id, - [GLOBAL_SEARCH_META_KEYS.IMPORTANCE]: GLOBAL_SEARCH_IMPORTANCE.DOCS, + [globalSearchMetaKeys.version]: activeVersion.id, + [globalSearchMetaKeys.importance]: globalSearchImportance.docs, }, }; } @@ -37,7 +37,7 @@ const latestVersionId = latestVersion.id; export const generateStaticParams = () => { const result: { slug: string[] }[] = []; - const tree = generateDocsTree(); + const tree = getDocsTreeFromPath(); const getSlugs = (data: TreeProps[]) => { data.forEach((item) => { @@ -86,10 +86,10 @@ export default async function Page({ params: { slug } }: PageProps) { return ( <> -
+
{!isLatest && ( -
+
You are viewing documentation for a previous version of Storybook )}

{page.title || 'Title is missing'} diff --git a/apps/frontpage/app/docs/layout.tsx b/apps/frontpage/app/docs/layout.tsx index 3ebf4b3a..fe8735e7 100644 --- a/apps/frontpage/app/docs/layout.tsx +++ b/apps/frontpage/app/docs/layout.tsx @@ -2,9 +2,8 @@ import { Header, Footer, Container } from '@repo/ui'; import Image from 'next/image'; import { fetchGithubCount } from '@repo/utils'; import { Sidebar } from '../../components/docs/sidebar/sidebar'; -import { TableOfContent } from '../../components/docs/table-of-content'; import { NavDocs } from '../../components/docs/sidebar/docs-nav'; -import { generateDocsTree } from '../../lib/get-tree'; +import { getDocsTreeFromPath } from '../../lib/get-docs-tree-from-path'; import { DocsProvider } from './provider'; import { Submenu } from '../../components/docs/submenu'; import { DocsMainNav } from '../../components/docs/sidebar/docs-main-nav'; @@ -17,13 +16,6 @@ export default async function Layout({ children }: { children: ReactNode }) { const { number: githubCount } = await fetchGithubCount(); const listofTrees = getAllTrees(); - // const listofTrees = docsVersions.map((version) => { - // return { - // version: version.id, - // tree: getDocsTreeFromPath(`content/docs/${version.id}`), - // }; - // }); - return (
{ - const tree = generateDocsTree(`content/docs/${v}`); + const tree = getDocsTreeFromPath(`content/docs/${v}`); addSlugs(tree); }); diff --git a/apps/frontpage/lib/get-tree.ts b/apps/frontpage/lib/get-docs-tree-from-path.ts similarity index 94% rename from apps/frontpage/lib/get-tree.ts rename to apps/frontpage/lib/get-docs-tree-from-path.ts index 26c01b67..49a3cbe1 100644 --- a/apps/frontpage/lib/get-tree.ts +++ b/apps/frontpage/lib/get-docs-tree-from-path.ts @@ -23,7 +23,10 @@ function shouldParse(fileOrPath: string) { return !fileOrPath.endsWith('/versions'); } -export const generateDocsTree = (pathToFiles?: string, docsRoot?: string) => { +export const getDocsTreeFromPath = ( + pathToFiles?: string, + docsRoot?: string, +) => { const newPath = pathToFiles || 'content/docs'; const newDocsRoot = docsRoot || newPath; @@ -36,7 +39,7 @@ export const generateDocsTree = (pathToFiles?: string, docsRoot?: string) => { const isDirectory = fs.lstatSync(filePath).isDirectory(); if (isDirectory) { - const childItems = generateDocsTree(filePath, newDocsRoot); + const childItems = getDocsTreeFromPath(filePath, newDocsRoot); if (childItems) { const indexFile = childItems.find( diff --git a/apps/frontpage/lib/get-page.tsx b/apps/frontpage/lib/get-page.tsx index 26581ff2..c7b1284b 100644 --- a/apps/frontpage/lib/get-page.tsx +++ b/apps/frontpage/lib/get-page.tsx @@ -14,7 +14,7 @@ import { Video, YouTubeCallout, } from '../components/docs/mdx'; -import { generateDocsTree } from './get-tree'; +import { getDocsTreeFromPath } from './get-docs-tree-from-path'; export const getPageData = async ( path: string[], @@ -91,7 +91,7 @@ export const getPageData = async ( ? `${rootPath}/${pathString}`.split('/').slice(0, -1).join('/') : `${rootPath}/${pathString}`; - const parent = generateDocsTree(pathToFiles); + const parent = getDocsTreeFromPath(pathToFiles); const sorted = parent.sort((a, b) => a.tab?.order && b.tab?.order ? a.tab.order - b.tab.order : 0, diff --git a/packages/ui/src/constants.ts b/packages/ui/src/constants.ts index f982e365..081fbb00 100644 --- a/packages/ui/src/constants.ts +++ b/packages/ui/src/constants.ts @@ -1,11 +1,11 @@ -export const GLOBAL_SEARCH_META_KEYS = { - VERSION: 'docsearch:version', - IMPORTANCE: 'docsearch:importance', +export const globalSearchMetaKeys = { + version: 'docsearch:version', + importance: 'docsearch:importance', }; -export const GLOBAL_SEARCH_AGNOSTIC = 'agnostic'; +export const globalSearchAgnostic = 'agnostic'; -export const GLOBAL_SEARCH_IMPORTANCE = { - DOCS: 0, - AGNOSTIC: 1, +export const globalSearchImportance = { + docs: 0, + agnostic: 1, }; diff --git a/packages/ui/src/search/index.tsx b/packages/ui/src/search/index.tsx index 38507800..a034d025 100644 --- a/packages/ui/src/search/index.tsx +++ b/packages/ui/src/search/index.tsx @@ -5,7 +5,7 @@ import { DocSearch } from '@docsearch/react'; import { cn, getVersion } from '@repo/utils'; import { useSelectedLayoutSegment } from 'next/navigation'; import type { HeaderProps } from '../header'; -import { GLOBAL_SEARCH_AGNOSTIC } from '../constants'; +import { globalSearchAgnostic } from '../constants'; interface SearchProps extends Pick { className?: string; @@ -113,10 +113,7 @@ export const Search: FC = ({ * between the containing values */ [`tags:docs`, `tags:recipes`], - [ - `version:${activeVersion.id}`, - `version:${GLOBAL_SEARCH_AGNOSTIC}`, - ], + [`version:${activeVersion.id}`, `version:${globalSearchAgnostic}`], ], }} translations={{