www: add frontmatter and meta description handling (#188)
This commit is contained in:
@@ -10,7 +10,7 @@ import {
|
|||||||
PageProps,
|
PageProps,
|
||||||
tw,
|
tw,
|
||||||
} from "../../client_deps.ts";
|
} 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 DocsSidebar from "../../components/DocsSidebar.tsx";
|
||||||
import Footer from "../../components/Footer.tsx";
|
import Footer from "../../components/Footer.tsx";
|
||||||
import NavigationBar from "../../components/NavigationBar.tsx";
|
import NavigationBar from "../../components/NavigationBar.tsx";
|
||||||
@@ -27,6 +27,7 @@ interface Data {
|
|||||||
|
|
||||||
interface Page extends TableOfContentsEntry {
|
interface Page extends TableOfContentsEntry {
|
||||||
markdown: string;
|
markdown: string;
|
||||||
|
data: Record<string, unknown>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const handler: Handlers<Data> = {
|
export const handler: Handlers<Data> = {
|
||||||
@@ -45,19 +46,30 @@ export const handler: Handlers<Data> = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
const url = new URL(`../../../${entry.file}`, import.meta.url);
|
const url = new URL(`../../../${entry.file}`, import.meta.url);
|
||||||
const markdown = await Deno.readTextFile(url);
|
const fileContent = await Deno.readTextFile(url);
|
||||||
const page = { ...entry, markdown };
|
const { content, data } = frontMatter(fileContent) as {
|
||||||
|
data: Record<string, string>;
|
||||||
|
content: string;
|
||||||
|
};
|
||||||
|
const page = { ...entry, markdown: content, data: data ?? {} };
|
||||||
const resp = ctx.render({ page });
|
const resp = ctx.render({ page });
|
||||||
return resp;
|
return resp;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function DocsPage(props: PageProps<Data>) {
|
export default function DocsPage(props: PageProps<Data>) {
|
||||||
|
let description;
|
||||||
|
|
||||||
|
if (props.data.page.data.description) {
|
||||||
|
description = String(props.data.page.data.description);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Head>
|
<Head>
|
||||||
<title>{props.data.page?.title ?? "Not Found"} | fresh docs</title>
|
<title>{props.data.page?.title ?? "Not Found"} | fresh docs</title>
|
||||||
<link rel="stylesheet" href={`/gfm.css?build=${__FRSH_BUILD_ID}`} />
|
<link rel="stylesheet" href={`/gfm.css?build=${__FRSH_BUILD_ID}`} />
|
||||||
|
{description && <meta name="description" content={description} />}
|
||||||
</Head>
|
</Head>
|
||||||
<Header />
|
<Header />
|
||||||
<NavigationBar active="/docs" />
|
<NavigationBar active="/docs" />
|
||||||
|
|||||||
@@ -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-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-typescript.js?no-check";
|
||||||
import "https://esm.sh/prismjs@1.27.0/components/prism-tsx.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";
|
||||||
|
|||||||
Reference in New Issue
Block a user