diff --git a/packages/fdr-sdk/src/converters/db/convertDocsDefinitionToDb.ts b/packages/fdr-sdk/src/converters/db/convertDocsDefinitionToDb.ts index fc655f84cf..d04015c997 100644 --- a/packages/fdr-sdk/src/converters/db/convertDocsDefinitionToDb.ts +++ b/packages/fdr-sdk/src/converters/db/convertDocsDefinitionToDb.ts @@ -145,14 +145,15 @@ function transformUnversionedNavigationConfigForDb( untabbed: (config) => { return { items: config.items.map(transformNavigationItemForDb), - landingPage: transformPageNavigationItemForDb(config.landingPage), + // landing page's slug should be "" because it's the root + landingPage: transformPageNavigationItemForDb(config.landingPage, ""), }; }, tabbed: (config) => { return { tabs: config.tabs?.map(transformNavigationTabForDb), tabsV2: config.tabsV2?.map(transformNavigationTabV2ForDb), - landingPage: transformPageNavigationItemForDb(config.landingPage), + landingPage: transformPageNavigationItemForDb(config.landingPage, ""), }; }, }); @@ -463,12 +464,15 @@ function transformColorsV3ForDb({ function transformPageNavigationItemForDb( writeShape: DocsV1Write.PageMetadata, + defaultSlug?: string, ): WithoutQuestionMarks; function transformPageNavigationItemForDb( writeShape: DocsV1Write.PageMetadata | undefined, + defaultSlug?: string, ): WithoutQuestionMarks | undefined; function transformPageNavigationItemForDb( writeShape: DocsV1Write.PageMetadata | undefined, + defaultSlug?: string, ): WithoutQuestionMarks | undefined { if (writeShape == null) { return undefined; @@ -478,7 +482,7 @@ function transformPageNavigationItemForDb( id: writeShape.id, title: writeShape.title, icon: writeShape.icon, - urlSlug: writeShape.urlSlugOverride ?? kebabCase(writeShape.title), + urlSlug: writeShape.urlSlugOverride ?? defaultSlug ?? kebabCase(writeShape.title), fullSlug: writeShape.fullSlug, hidden: writeShape.hidden ?? false, }; diff --git a/packages/fdr-sdk/src/navigation/utils/findNode.ts b/packages/fdr-sdk/src/navigation/utils/findNode.ts index 23061b037d..ad301cfda9 100644 --- a/packages/fdr-sdk/src/navigation/utils/findNode.ts +++ b/packages/fdr-sdk/src/navigation/utils/findNode.ts @@ -24,6 +24,7 @@ export declare namespace Node { next: NavigationNodeNeighbor | undefined; prev: NavigationNodeNeighbor | undefined; collector: NodeCollector; + landingPage: FernNavigation.LandingPageNode | undefined; } interface Redirect { @@ -56,13 +57,14 @@ export function findNode(root: FernNavigation.RootNode, slug: string[]): Node { const sidebar = found.parents.find((node): node is FernNavigation.SidebarRootNode => node.type === "sidebarRoot"); const currentVersion = found.parents.find((node): node is FernNavigation.VersionNode => node.type === "version"); + const tabbedNode = found.parents.find((node): node is FernNavigation.TabbedNode => node.type === "tabbed"); + const unversionedNode = found.parents.find( + (node): node is FernNavigation.UnversionedNode => node.type === "unversioned", + ); + const landingPage = (currentVersion ?? unversionedNode)?.landingPage; if (isPage(found.node)) { - const rootChild = (currentVersion ?? root).child; const parentsAndNode = [...found.parents, found.node]; - const tabs = rootChild.type === "tabbed" ? rootChild.children : []; - const tabbedNodeIndex = parentsAndNode.findIndex( - (node): node is FernNavigation.TabbedNode => node.type === "tabbed", - ); + const tabbedNodeIndex = parentsAndNode.findIndex((node) => node === tabbedNode); const currentTab = tabbedNodeIndex !== -1 ? parentsAndNode[tabbedNodeIndex + 1] : undefined; return { type: "found", @@ -82,13 +84,14 @@ export function findNode(root: FernNavigation.RootNode, slug: string[]): Node { } return node; }), - tabs, + tabs: tabbedNode?.children ?? [], currentVersion, currentTab: currentTab?.type === "tab" || currentTab?.type === "changelog" ? currentTab : undefined, sidebar, apiReference: found.parents.find((node): node is FernNavigation.ApiReferenceNode => node.type === "apiReference") ?? (found.node.type === "apiReference" ? found.node : undefined), + landingPage, next: found.next, prev: found.prev, collector, diff --git a/packages/ui/docs-bundle/src/utils/getDocsPageProps.ts b/packages/ui/docs-bundle/src/utils/getDocsPageProps.ts index cf01b50b55..53d275791b 100644 --- a/packages/ui/docs-bundle/src/utils/getDocsPageProps.ts +++ b/packages/ui/docs-bundle/src/utils/getDocsPageProps.ts @@ -249,7 +249,9 @@ async function convertDocsToDocsPageProps({ js: docs.definition.config.js, navbarLinks: docs.definition.config.navbarLinks ?? [], logoHeight: docs.definition.config.logoHeight, - logoHref: docs.definition.config.logoHref, + logoHref: + docs.definition.config.logoHref ?? + (node.landingPage?.slug != null && !node.landingPage.hidden ? `/${node.landingPage.slug}` : undefined), search: docs.definition.search, files: docs.definition.filesV2, resolvedPath,