Compare commits

..

No commits in common. "668f73069218a4477ce84a72c67e879c089a22c4" and "115ab1b45be4ca60358f55d20a491629700dd96a" have entirely different histories.

4 changed files with 14 additions and 19 deletions

View File

@ -133,7 +133,7 @@ export function doesLinkSubitemExist(link: NavigationLink, subitemHref: string):
return link.subitems.some((subitem) => subitem.href === subitemHref); return link.subitems.some((subitem) => subitem.href === subitemHref);
} }
export function findNavigationLink(namespace: string, href?: string): NavigationLink | undefined { export function findNavigationLink(namespace: string, href: string): NavigationLink | undefined {
const currentUrl = `/${namespace}/${href}`.replace(/\/+/g, "/").replace(/\/$/, ""); const currentUrl = `/${namespace}/${href}`.replace(/\/+/g, "/").replace(/\/$/, "");
const foundLink = navigation const foundLink = navigation

View File

@ -4,7 +4,7 @@ const routeRegex = /^\/docs\/(.*)$/;
export function route(pageContext: PageContext) { export function route(pageContext: PageContext) {
if (pageContext.urlPathname === "/docs") { if (pageContext.urlPathname === "/docs") {
return { routeParams: { key: "index" } }; return { routeParams: { key: "documentations" } };
} }
const match = pageContext.urlPathname.match(routeRegex); const match = pageContext.urlPathname.match(routeRegex);

View File

@ -12,8 +12,11 @@ export type Data = Awaited<ReturnType<typeof data>>;
export async function data(_pageContext: PageContext) { export async function data(_pageContext: PageContext) {
const config = useConfig(); const config = useConfig();
const doc = await docsService.getDoc("root"); const doc = await docsService.getDoc("docs", "index");
if (!doc) throw render(404);
if (!doc) {
throw render(404);
}
const readingTimeObject = readingTime(doc.content, 300, "fr"); const readingTimeObject = readingTime(doc.content, 300, "fr");

View File

@ -109,19 +109,16 @@ class DocsService {
public async fetchDocs() { public async fetchDocs() {
const docs = glob.sync(DocsService.DOCS_PATH + `/**/*.{${DocsService.DOCS_EXTS.join(",")}}`); const docs = glob.sync(DocsService.DOCS_PATH + `/**/*.{${DocsService.DOCS_EXTS.join(",")}}`);
const data = await Promise.all( const data = await Promise.all(
docs.map((doc) => { docs.map((doc) => {
const content = fs.readFileSync(doc, "utf-8"); const content = fs.readFileSync(doc, "utf-8");
const extension = path.extname(doc).slice(1) as DocExtension; const extension = path.extname(doc).slice(1) as DocExtension;
let key = doc const key = doc
.replace(DocsService.DOCS_PATH, "") .replace(DocsService.DOCS_PATH, "")
.replace(`page.${extension}`, "") .replace(`page.${extension}`, "")
.replace(`.${extension}`, "") .replace(`.${extension}`, "")
.replace(/\/$/g, ""); .replace(/\/$/g, "");
if (key === "") key = "/root";
const ast = Markdoc.parse(content); const ast = Markdoc.parse(content);
const title = ast.attributes?.frontmatter?.match(/^title:\s*(.*?)\s*$/m)?.[1]; const title = ast.attributes?.frontmatter?.match(/^title:\s*(.*?)\s*$/m)?.[1];
const description = ast.attributes?.frontmatter?.match(/^description:\s*(.*?)\s*$/m)?.[1]?.replaceAll('"', ""); const description = ast.attributes?.frontmatter?.match(/^description:\s*(.*?)\s*$/m)?.[1]?.replaceAll('"', "");
@ -152,28 +149,23 @@ class DocsService {
}; };
} }
public async getDoc(namespace: "root" | "docs" | "certifications", key?: string): Promise<DocData | undefined> { public async getDoc(namespace: "docs" | "certifications", key: string) {
try { try {
await this.fetchDocs(); await this.fetchDocs();
let doc: DocData | undefined; const doc = this.getFromCache(`/${namespace}/${key}`);
if (namespace === "root" || key === "index") { if (!doc) {
doc = this.getFromCache(`/${namespace}`); throw new Error("Doc not found");
} else {
doc = this.getFromCache(`/${namespace}/${key}`);
} }
if (!doc) throw new Error("Doc not found");
return doc; return doc;
} catch (error) { } catch (error) {
console.error("Error fetching docs:", error); console.error("Error fetching docs:", error);
return null;
return undefined;
} }
} }
public async getUrls(namespace: "root" | "docs" | "certifications") { public async getUrls(namespace: "docs" | "certifications") {
try { try {
await this.fetchDocs(); await this.fetchDocs();
const docs = Array.from(this.cache.keys()).filter((key) => key.startsWith(`/${namespace}`)); const docs = Array.from(this.cache.keys()).filter((key) => key.startsWith(`/${namespace}`));