diff --git a/app/components/PageHeaderLinks.vue b/app/components/PageHeaderLinks.vue new file mode 100644 index 0000000..30a2dad --- /dev/null +++ b/app/components/PageHeaderLinks.vue @@ -0,0 +1,84 @@ + + + diff --git a/app/pages/[...slug].vue b/app/pages/[...slug].vue index 019289d..156136c 100644 --- a/app/pages/[...slug].vue +++ b/app/pages/[...slug].vue @@ -57,9 +57,18 @@ const links = computed(() => { + > + + { + const slug = getRouterParams(event)['slug.md'] + if (!slug?.endsWith('.md')) { + throw createError({ statusCode: 404, statusMessage: 'Page not found', fatal: true }) + } + + const path = withLeadingSlash(slug.replace('.md', '')) + + const page = await queryCollection(event, 'docs' as keyof Collections).path(path).first() + if (!page) { + throw createError({ statusCode: 404, statusMessage: 'Page not found', fatal: true }) + } + + // Add title and description to the top of the page if missing + if (page.body.value[0]?.[0] !== 'h1') { + page.body.value.unshift(['blockquote', {}, page.description]) + page.body.value.unshift(['h1', {}, page.title]) + } + + setHeader(event, 'Content-Type', 'text/markdown; charset=utf-8') + return stringify({ ...page.body, type: 'minimark' }, { format: 'markdown/html' }) +})