diff --git a/www/routes/docs/[...slug].tsx b/www/routes/docs/[...slug].tsx index 72d60eb4..28586a13 100644 --- a/www/routes/docs/[...slug].tsx +++ b/www/routes/docs/[...slug].tsx @@ -10,7 +10,7 @@ import { PageProps, tw, } from "../../client_deps.ts"; -import { gfm, Handlers } from "../../server_deps.ts"; +import { frontMatter, gfm, Handlers } from "../../server_deps.ts"; import DocsSidebar from "../../components/DocsSidebar.tsx"; import Footer from "../../components/Footer.tsx"; import NavigationBar from "../../components/NavigationBar.tsx"; @@ -27,6 +27,7 @@ interface Data { interface Page extends TableOfContentsEntry { markdown: string; + data: Record; } export const handler: Handlers = { @@ -45,19 +46,30 @@ export const handler: Handlers = { }); } const url = new URL(`../../../${entry.file}`, import.meta.url); - const markdown = await Deno.readTextFile(url); - const page = { ...entry, markdown }; + const fileContent = await Deno.readTextFile(url); + const { content, data } = frontMatter(fileContent) as { + data: Record; + content: string; + }; + const page = { ...entry, markdown: content, data: data ?? {} }; const resp = ctx.render({ page }); return resp; }, }; export default function DocsPage(props: PageProps) { + let description; + + if (props.data.page.data.description) { + description = String(props.data.page.data.description); + } + return ( <> {props.data.page?.title ?? "Not Found"} | fresh docs + {description && }
diff --git a/www/server_deps.ts b/www/server_deps.ts index 8779a83a..b5fb5019 100644 --- a/www/server_deps.ts +++ b/www/server_deps.ts @@ -6,3 +6,5 @@ export * as gfm from "https://deno.land/x/gfm@0.1.19/mod.ts"; import "https://esm.sh/prismjs@1.27.0/components/prism-jsx.js?no-check"; import "https://esm.sh/prismjs@1.27.0/components/prism-typescript.js?no-check"; import "https://esm.sh/prismjs@1.27.0/components/prism-tsx.js?no-check"; + +export { parse as frontMatter } from "https://deno.land/x/frontmatter@v0.1.4/mod.ts";