Skip to content

Commit 9ef32ad

Browse files
committed
Add error logging to docs loader for runtime diagnostics
Surfaces parseFrontmatter failures (gray-matter browser compat), empty glob results, and missing slugs to the console so the real cause of 'No documentation pages found' is visible in DevTools. Each doc's title now falls back to slug-derived when frontmatter fails, so at worst the sidebar still populates with slug-cased names.
1 parent 6e2110c commit 9ef32ad

2 files changed

Lines changed: 59 additions & 31 deletions

File tree

site/src/lib/docs-content.ts

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,41 @@ export async function buildNavSections(): Promise<NavSection[]> {
8181

8282
navPromise = (async () => {
8383
const docs = listDocs()
84+
85+
if (docs.length === 0) {
86+
console.warn(
87+
'[proofread/docs] import.meta.glob returned no markdown files. ' +
88+
'Module keys:',
89+
Object.keys(modules),
90+
)
91+
}
92+
8493
const sources = await Promise.all(
8594
docs.map(async (doc) => {
86-
const source = await doc.load()
87-
const { data, content } = parseFrontmatter(source)
88-
const slugFallback = doc.slug
89-
.split('/')
90-
.pop()!
91-
.replace(/-/g, ' ')
92-
.replace(/\b\w/g, (c) => c.toUpperCase())
93-
const title = data.title ?? titleFromSource(content, slugFallback)
95+
let title: string
96+
let section = ''
97+
try {
98+
const source = await doc.load()
99+
const { data, content } = parseFrontmatter(source)
100+
section = data.section ?? ''
101+
const slugFallback = doc.slug
102+
.split('/')
103+
.pop()!
104+
.replace(/-/g, ' ')
105+
.replace(/\b\w/g, (c) => c.toUpperCase())
106+
title = data.title ?? titleFromSource(content, slugFallback)
107+
} catch (err) {
108+
console.error(`[proofread/docs] Failed to load ${doc.path}:`, err)
109+
title = doc.slug
110+
.split('/')
111+
.pop()!
112+
.replace(/-/g, ' ')
113+
.replace(/\b\w/g, (c) => c.toUpperCase())
114+
}
94115
return {
95116
slug: doc.slug,
96117
title,
97-
section: data.section ?? '',
118+
section,
98119
}
99120
}),
100121
)

site/src/pages/DocsPage.vue

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,30 +61,37 @@ async function load(): Promise<void> {
6161
return
6262
}
6363
64-
const source = await loadDoc(current)
65-
if (!source) {
64+
try {
65+
const source = await loadDoc(current)
66+
if (!source) {
67+
console.warn(`[proofread/docs] No doc matches slug "${current}".`)
68+
notFound.value = true
69+
title.value = 'Page not found'
70+
description.value = SITE_DESCRIPTION
71+
return
72+
}
73+
74+
const rendered = await renderMarkdown(source)
75+
html.value = rendered.html
76+
toc.value = rendered.toc
77+
title.value = rendered.title || current
78+
description.value = extractDescription(source) || SITE_DESCRIPTION
79+
80+
const sections = await buildNavSections()
81+
const items: NavItem[] = sections.flatMap((s) => s.items)
82+
const index = items.findIndex((i) => i.slug === current)
83+
if (index > 0) prev.value = items[index - 1]
84+
if (index >= 0 && index < items.length - 1) next.value = items[index + 1]
85+
86+
await nextTick()
87+
if (route.hash) {
88+
const el = document.querySelector(route.hash)
89+
if (el) el.scrollIntoView({ behavior: 'smooth', block: 'start' })
90+
}
91+
} catch (err) {
92+
console.error(`[proofread/docs] Failed to load doc "${current}":`, err)
6693
notFound.value = true
6794
title.value = 'Page not found'
68-
description.value = SITE_DESCRIPTION
69-
return
70-
}
71-
72-
const rendered = await renderMarkdown(source)
73-
html.value = rendered.html
74-
toc.value = rendered.toc
75-
title.value = rendered.title || current
76-
description.value = extractDescription(source) || SITE_DESCRIPTION
77-
78-
const sections = await buildNavSections()
79-
const items: NavItem[] = sections.flatMap((s) => s.items)
80-
const index = items.findIndex((i) => i.slug === current)
81-
if (index > 0) prev.value = items[index - 1]
82-
if (index >= 0 && index < items.length - 1) next.value = items[index + 1]
83-
84-
await nextTick()
85-
if (route.hash) {
86-
const el = document.querySelector(route.hash)
87-
if (el) el.scrollIntoView({ behavior: 'smooth', block: 'start' })
8895
}
8996
}
9097

0 commit comments

Comments
 (0)