From 9aa990e10ccb04c5d6908fe18d53dd82d581b178 Mon Sep 17 00:00:00 2001 From: gumi Date: Fri, 9 Oct 2020 22:53:19 -0400 Subject: update for the latest version of the markdown module --- src/build.ts | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/src/build.ts b/src/build.ts index 4749057..fb90814 100644 --- a/src/build.ts +++ b/src/build.ts @@ -1,5 +1,4 @@ import { Marked } from "https://deno.land/x/markdown/mod.ts" -import * as yaml from "https://deno.land/x/js_yaml_port/js-yaml.js" // the structure of the front matter interface PolicyYFM { @@ -51,33 +50,22 @@ await Deno.remove("build", { recursive: true }); // loop through policy files for await (const dirEntry of Deno.readDir("policies")) { const file = dirEntry.name; - const rawPolicy = decoder.decode(await Deno.readFile(`policies/${file}`)); + const [shortName, type] = file.split("."); - if (!rawPolicy.trimStart().startsWith("---")) { - console.log(`Ignoring policy file with no front matter: ${file}`); + if (type.toLowerCase() !== "md") { + console.log(`Unsupported policy file format: ${file}`); continue; } - // find the closing tag - const endFrontMatter = rawPolicy.slice(3).indexOf("---"); - - if (endFrontMatter === -1) { - throw new SyntaxError(`Couldn't find end of front matter in ${file}`); - } - - // mark the boundaries - const rawYAML = rawPolicy.slice(3, endFrontMatter + 3).trim(); - const rawBody = rawPolicy.slice(3 + endFrontMatter + 3).trim(); - - const [shortName, type] = file.split("."); + const rawPolicy = decoder.decode(await Deno.readFile(`policies/${file}`)); - if (type.toLowerCase() !== "md") { - console.log(`Unsupported policy file format: ${file}`); + if (!rawPolicy.trimStart().startsWith("---")) { + console.log(`Ignoring policy file with no front matter: ${file}`); continue; } - // parse the front matter as yaml - const YFM: PolicyYFM = yaml.safeLoad(rawYAML, {filename: file}); + // parse front matter and markdown: + const {content: html, meta: YFM} = Marked.parse(rawPolicy); if (Reflect.has(YFM, "ignore") || file.startsWith(".")) { console.log(`Ignoring disabled policy file: ${file}`); @@ -108,9 +96,6 @@ for await (const dirEntry of Deno.readDir("policies")) { } } - // convert from markdown to html - const html: string = Marked.parse(rawBody); - // wrap the generated html inside our template const policyPage = encoder.encode(` -- cgit v1.2.3-70-g09d2