fix: section menu link

This commit is contained in:
Baptiste Augrain
2025-05-13 00:34:48 +02:00
parent eaa01fbf40
commit 2dfbe21862
2 changed files with 20 additions and 7 deletions

View File

@@ -72,8 +72,7 @@ export function DocumentationSidebar({ pages }: DocumentationSidebarProperties)
return null;
}
const sectionUrl
= page.slug === 'index' ? `/docs#${section.slug}` : `/docs/${page.slug}#${section.slug}`;
const sectionUrl = section.slug ? (page.slug === 'index' ? `/docs#${section.slug}` : `/docs/${page.slug}#${section.slug}`) : section.url!;
return (
<li key={`${page.slug}-${section.slug}`}>

View File

@@ -31,8 +31,9 @@ export type TableOfContents = {
export type DocumentationSection = {
title: string;
slug: string;
level: number;
slug?: string;
url?: string;
};
export type DocumentationPageInfo = {
@@ -46,7 +47,7 @@ export type DocumentationPageInfo = {
// Function to extract title from markdown content
function extractTitle(content: string): string {
const titleMatch = /^#\s+(.*)$/m.exec(content);
// return titleMatch ? titleMatch[1] : "Documentation"
if(titleMatch) {
return titleMatch[1];
}
@@ -102,16 +103,29 @@ function extractSections(content: string): DocumentationSection[] {
let [, hashes, slug, title] = match;
const level = hashes.length;
// Only include h2 and h3
if(level <= 3 && title !== 'Table of Contents') {
if((match = /\[(.*)]\((.*)\)/.exec(title))) {
const [, title, url] = match;
slug ||= slugify(title, { lower: true });
sections.push({
title,
slug,
level,
url,
});
}
else {
// Only include h2 and h3
if(level <= 3 && title !== 'Table of Contents') {
slug ||= slugify(title, { lower: true });
sections.push({
title,
level,
slug,
});
}
}
}
return sections;