From 2d92d85a7d90e6857c1c3eef17ba980457f4ef9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Heiko=20Thei=C3=9Fen?= Date: Wed, 10 Apr 2024 09:46:22 +0200 Subject: [PATCH] Allow dynamic URLs --- {styles => assets/styles}/style.css | 0 lib/md2html.js | 6 ++++++ lib/pages.js | 2 +- lib/pandoc.js | 15 +++++++++------ 4 files changed, 16 insertions(+), 7 deletions(-) rename {styles => assets/styles}/style.css (100%) diff --git a/styles/style.css b/assets/styles/style.css similarity index 100% rename from styles/style.css rename to assets/styles/style.css diff --git a/lib/md2html.js b/lib/md2html.js index 17d6ee29..9f78daea 100644 --- a/lib/md2html.js +++ b/lib/md2html.js @@ -3,6 +3,12 @@ const filter = require("pandoc-filter"); filter.stdio(function ({ t, c }, format, meta) { + /* Links with dynamic target: Edit this page [here](--editurl) */ + if (t === "Link" && c[2][0].startsWith("--")) { + c[2][0] = meta[c[2][0].substring(2)].c; + return filter.Link(...c); + } + /* Links to other converted documents */ if (t === "Link" && !/^https?:\/\//.test(c[2][0])) { c[2][0] = c[2][0].replace(/\.md(?=$|#)/, ".html"); return filter.Link(...c); diff --git a/lib/pages.js b/lib/pages.js index 04545d6c..83289dbc 100644 --- a/lib/pages.js +++ b/lib/pages.js @@ -33,7 +33,7 @@ function directory(dir) { } } -fs.cpSync(`${__dirname}/../styles`, `${__dirname}/../_site/styles`, { +fs.cpSync(`${__dirname}/../assets/styles`, `${__dirname}/../_site/styles`, { recursive: true, }); diff --git a/lib/pandoc.js b/lib/pandoc.js index 36e47f4e..4f9187bb 100644 --- a/lib/pandoc.js +++ b/lib/pandoc.js @@ -1,6 +1,8 @@ const { spawn } = require("child_process"); function pandoc({ stdin, stdout }, options = {}) { + var footer = options.footer || ""; + delete options.footer; var mermaidOptions = { startOnLoad: false, ...options.mermaid }; delete options.mermaid; var opts = [ @@ -13,12 +15,12 @@ function pandoc({ stdin, stdout }, options = {}) { "--eol=lf", "--wrap=none", ]; - for (var param in options) { - var value = options[param]; - if (value && param.startsWith("--")) opts.push(param + "=" + value); - else if (value && param.startsWith("-")) opts.push(param, value); - else opts.push(param); - } + for (var param in options) + [].concat(options[param]).forEach(function (value) { + if (value && param.startsWith("--")) opts.push(param + "=" + value); + else if (value && param.startsWith("-")) opts.push(param, value); + else opts.push(param); + }); var proc = spawn("pandoc", opts); proc.stderr.on("data", function (err) { console.error(err.toString()); @@ -27,6 +29,7 @@ function pandoc({ stdin, stdout }, options = {}) { stdin .on("end", function () { proc.stdin.end(` +${footer}