feat: Add prerender functionality and onBeforePrerenderStart

This commit is contained in:
Gauthier Daniels 2025-04-17 13:55:20 +02:00
parent 641e1e8a13
commit 234ee24e3f
4 changed files with 24 additions and 0 deletions

View File

@ -23,6 +23,7 @@ export default {
class: "flex min-h-full bg-white dark:bg-slate-900",
},
prerender: true,
prefetchStaticAssets: "hover",
extends: vikeReact,

View File

@ -0,0 +1,6 @@
import { docsService } from "@/services/DocsService";
export async function onBeforePrerenderStart() {
const allDocumentations = await docsService.getUrls("certifications");
return allDocumentations;
}

View File

@ -0,0 +1,6 @@
import { docsService } from "@/services/DocsService";
export async function onBeforePrerenderStart() {
const allDocumentations = await docsService.getUrls("docs");
return allDocumentations;
}

View File

@ -164,6 +164,17 @@ class DocsService {
return null;
}
}
public async getUrls(namespace: "docs" | "certifications") {
try {
await this.fetchDocs();
const docs = Array.from(this.cache.keys()).filter((key) => key.startsWith(`/${namespace}`));
return docs;
} catch (error) {
console.error("Error fetching URLs:", error);
return [];
}
}
}
export const docsService = DocsService.getInstance();