summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgumi <git@gumi.ca>2020-10-09 22:53:19 -0400
committergumi <git@gumi.ca>2020-10-09 22:53:19 -0400
commit9aa990e10ccb04c5d6908fe18d53dd82d581b178 (patch)
treea06795ca1fb717745ae056860604dae7ba6c066e
parente128784eddd9dea2e3a8afe7609ebcb3d6eadd52 (diff)
downloadpolicies-9aa990e10ccb04c5d6908fe18d53dd82d581b178.tar.gz
policies-9aa990e10ccb04c5d6908fe18d53dd82d581b178.tar.bz2
policies-9aa990e10ccb04c5d6908fe18d53dd82d581b178.tar.xz
policies-9aa990e10ccb04c5d6908fe18d53dd82d581b178.zip
update for the latest version of the markdown module
-rw-r--r--src/build.ts31
1 files 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(`
<!doctype html>