memento-dev/app/pages/+data.ts
GauthierWebDev a30927a633
All checks were successful
Update Memento Dev on VPS / deploy (push) Successful in 48s
docs/js (#26)
Reviewed-on: #26
Co-authored-by: GauthierWebDev <gauthier@gauthierdaniels.fr>
Co-committed-by: GauthierWebDev <gauthier@gauthierdaniels.fr>
2025-06-09 13:14:56 +00:00

46 lines
1.1 KiB
TypeScript

import type { PageContext } from "vike/types";
import { useConfig } from "vike-solid/useConfig";
import { docCache } from "@/services/DocCache";
import buildTitle from "./buildTitle";
export type Data = Awaited<ReturnType<typeof data>>;
export async function data(pageContext: PageContext) {
const config = useConfig();
await docCache.waitingForCache(20000);
const {
exports: { frontmatter },
urlParsed,
} = pageContext;
const isRoot = urlParsed.pathname === "/";
config({
title: buildTitle(isRoot ? undefined : frontmatter?.title),
description: frontmatter?.description,
});
let cachePathname = urlParsed.pathname.replace(/\/$/, "").replace(/^\//, "");
if (cachePathname === "") cachePathname = "index";
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,
docs: docCache.orderByLastEdit({
limit: 2,
includedBasePaths: ["docs", "certifications"],
excludedFileNames: [cachePathname, "docs", "certifications"],
}),
};
}