Skip to content

Commit 668e27c

Browse files
committed
fix: be more robust about finding sections
#322 and #331 added pages for compiler/runtime errors/warnings, but these pages are barely usable because "On this page" is empty because of missing h2 tags. This fixes that by enhancing our sections logic: If no h2 tags are found, try again with h3 tags.
1 parent 3576454 commit 668e27c

File tree

1 file changed

+10
-1
lines changed
  • packages/site-kit/src/lib/server/content

1 file changed

+10
-1
lines changed

packages/site-kit/src/lib/server/content/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,21 @@ export async function create_index(
3131
'<code>$1</code>'
3232
);
3333

34-
const sections = Array.from(body.matchAll(/^##\s+(.*)$/gm)).map((match) => {
34+
let sections = Array.from(body.matchAll(/^##\s+(.*)$/gm)).map((match) => {
3535
const title = match[1].replace(/`/g, '').replace(/&lt;/g, '<').replace(/&gt;/g, '>');
3636
const slug = slugify(title);
3737

3838
return { slug, title };
3939
});
40+
// If no sections found, try again with sub sections. This way we have a better "OnThisPage" list
41+
if (sections.length === 0) {
42+
sections = Array.from(body.matchAll(/^###\s+(.*)$/gm)).map((match) => {
43+
const title = match[1].replace(/`/g, '').replace(/&lt;/g, '<').replace(/&gt;/g, '>');
44+
const slug = slugify(title);
45+
46+
return { slug, title };
47+
});
48+
}
4049

4150
content[slug] = {
4251
slug,

0 commit comments

Comments
 (0)