refactor: Improve function handling in PrevNextLinks file

This commit is contained in:
Gauthier Daniels 2025-04-21 14:53:12 +02:00
parent 4cab7bb6ed
commit 4625a92206
4 changed files with 40 additions and 16 deletions

View File

@ -1,3 +1,4 @@
import type { NavigationSubItem } from "@/libs/navigation";
import type { JSX } from "solid-js";
import { usePageContext } from "vike-solid/usePageContext";
@ -21,7 +22,8 @@ type PageLinkProps = Omit<JSX.IntrinsicElements["div"], "dir" | "title"> & {
};
function PageLink(props: PageLinkProps) {
const pageCategory = navigation.find((section) => {
const getPageCategory = () =>
navigation.find((section) => {
return section.links.some(
(link) =>
link.href === props.href ||
@ -43,9 +45,9 @@ function PageLink(props: PageLinkProps) {
)}
>
<p class="flex flex-col gap-0">
{pageCategory && (
{getPageCategory() && (
<span class="text-violet-600 text-sm mb-1 leading-3">
{pageCategory.title}
{getPageCategory()?.title}
</span>
)}
<span class="leading-4">{props.title}</span>
@ -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 (
<dl class="mt-12 flex gap-4 border-t border-slate-200 pt-6">
{previousPage && <PageLink dir="previous" {...previousPage} />}
{nextPage && <PageLink class="ml-auto text-right" {...nextPage} />}
{getNeighboringLinks()[0] && (
<PageLink
dir="previous"
{...(getNeighboringLinks()[0] as NavigationSubItem)}
/>
)}
{getNeighboringLinks()[1] && (
<PageLink
class="ml-auto text-right"
{...(getNeighboringLinks()[1] as NavigationSubItem)}
/>
)}
</dl>
);
}

View File

@ -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();

View File

@ -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<ReturnType<typeof data>>;
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,

View File

@ -16,7 +16,7 @@ Découvre donc de bons conseils pour t'aider à te préparer au mieux !
<QuickLinks.QuickLink
title="DWWM"
description="Titre professionnel Développeur Web et Web Mobile"
href="./dwwm"
href="certifications/dwwm"
icon="presets"
/>
</QuickLinks>