From 4625a9220694441824c813850deef06cdde382bb Mon Sep 17 00:00:00 2001 From: GauthierWebDev Date: Mon, 21 Apr 2025 14:53:12 +0200 Subject: [PATCH] refactor: Improve function handling in PrevNextLinks file --- app/components/PrevNextLinks.tsx | 38 ++++++++++++++++++++---------- app/layouts/DocsLayout.tsx | 7 +++++- app/pages/+data.ts | 9 ++++++- app/pages/certifications/+Page.mdx | 2 +- 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/app/components/PrevNextLinks.tsx b/app/components/PrevNextLinks.tsx index 51f7d8e..cda97ea 100644 --- a/app/components/PrevNextLinks.tsx +++ b/app/components/PrevNextLinks.tsx @@ -1,3 +1,4 @@ +import type { NavigationSubItem } from "@/libs/navigation"; import type { JSX } from "solid-js"; import { usePageContext } from "vike-solid/usePageContext"; @@ -21,13 +22,14 @@ type PageLinkProps = Omit & { }; function PageLink(props: PageLinkProps) { - const pageCategory = navigation.find((section) => { - return section.links.some( - (link) => - link.href === props.href || - link.subitems.some((subitem) => subitem.href === props.href), - ); - }); + const getPageCategory = () => + navigation.find((section) => { + return section.links.some( + (link) => + link.href === props.href || + link.subitems.some((subitem) => subitem.href === props.href), + ); + }); return (
@@ -43,9 +45,9 @@ function PageLink(props: PageLinkProps) { )} >

- {pageCategory && ( + {getPageCategory() && ( - {pageCategory.title} + {getPageCategory()?.title} )} {props.title} @@ -87,13 +89,23 @@ export function PrevNextLinks() { return [previousPage, nextPage]; }; - const [previousPage, nextPage] = getNeighboringLinks(); - if (!nextPage && !previousPage) return null; + if (getNeighboringLinks().length === 0) return null; return (

- {previousPage && } - {nextPage && } + {getNeighboringLinks()[0] && ( + + )} + + {getNeighboringLinks()[1] && ( + + )}
); } diff --git a/app/layouts/DocsLayout.tsx b/app/layouts/DocsLayout.tsx index 0016dea..0f2f261 100644 --- a/app/layouts/DocsLayout.tsx +++ b/app/layouts/DocsLayout.tsx @@ -1,8 +1,9 @@ import type { JSXElement } from "solid-js"; -import { TableOfContents } from "@/partials/TableOfContents"; +// import { TableOfContents } from "@/partials/TableOfContents"; import { PrevNextLinks } from "@/components/PrevNextLinks"; import { usePageContext } from "vike-solid/usePageContext"; +import { clientOnly } from "vike-solid/clientOnly"; import { clock } from "solid-heroicons/outline"; import { navigation } from "@/libs/navigation"; import { Prose } from "@/components/Prose"; @@ -12,6 +13,10 @@ type DocsLayoutProps = { children: JSXElement; }; +const TableOfContents = clientOnly( + async () => (await import("@/partials/TableOfContents")).TableOfContents, +); + export function DocsLayout(props: DocsLayoutProps) { const pageContext = usePageContext(); diff --git a/app/pages/+data.ts b/app/pages/+data.ts index 4912417..06c477e 100644 --- a/app/pages/+data.ts +++ b/app/pages/+data.ts @@ -1,4 +1,3 @@ -import type { SectionCache } from "@/services/DocCache"; import type { PageContext } from "vike/types"; import { useConfig } from "vike-solid/useConfig"; @@ -9,6 +8,7 @@ export type Data = Awaited>; export async function data(pageContext: PageContext) { const config = useConfig(); + await docCache.waitingForCache(20000); const { exports: { frontmatter }, @@ -28,6 +28,13 @@ export async function data(pageContext: PageContext) { const doc = docCache.get(cachePathname); + if (!doc) { + console.error( + `DocCache: No doc found for ${cachePathname}. This is a bug!`, + "Please report it to the maintainers.", + ); + } + return { sections: doc?.sections || [], frontmatter, diff --git a/app/pages/certifications/+Page.mdx b/app/pages/certifications/+Page.mdx index c680185..af871df 100644 --- a/app/pages/certifications/+Page.mdx +++ b/app/pages/certifications/+Page.mdx @@ -16,7 +16,7 @@ Découvre donc de bons conseils pour t'aider à te préparer au mieux !