www: add frontmatter and meta description handling (#188)

This commit is contained in:
Bartek Iwańczuk
2022-05-17 01:12:20 +02:00
committed by GitHub
parent cf438a7879
commit 86e0395369
2 changed files with 17 additions and 3 deletions
+15 -3
View File
@@ -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<string, unknown>;
}
export const handler: Handlers<Data> = {
@@ -45,19 +46,30 @@ export const handler: Handlers<Data> = {
});
}
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<string, string>;
content: string;
};
const page = { ...entry, markdown: content, data: data ?? {} };
const resp = ctx.render({ page });
return resp;
},
};
export default function DocsPage(props: PageProps<Data>) {
let description;
if (props.data.page.data.description) {
description = String(props.data.page.data.description);
}
return (
<>
<Head>
<title>{props.data.page?.title ?? "Not Found"} | fresh docs</title>
<link rel="stylesheet" href={`/gfm.css?build=${__FRSH_BUILD_ID}`} />
{description && <meta name="description" content={description} />}
</Head>
<Header />
<NavigationBar active="/docs" />
+2
View File
@@ -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";