Skip to content

Commit

Permalink
Allow dynamic URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
HeikoTheissen committed Apr 10, 2024
1 parent 9db308f commit 2d92d85
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
File renamed without changes.
6 changes: 6 additions & 0 deletions lib/md2html.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function directory(dir) {
}
}

fs.cpSync(`${__dirname}/../styles`, `${__dirname}/../_site/styles`, {
fs.cpSync(`${__dirname}/../assets/styles`, `${__dirname}/../_site/styles`, {
recursive: true,
});

Expand Down
15 changes: 9 additions & 6 deletions lib/pandoc.js
Original file line number Diff line number Diff line change
@@ -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 = [
Expand All @@ -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());
Expand All @@ -27,6 +29,7 @@ function pandoc({ stdin, stdout }, options = {}) {
stdin
.on("end", function () {
proc.stdin.end(`
${footer}
<script type="module">
document.addEventListener("DOMContentLoaded", function() {
document.body.classList.add("container-lg", "px-3", "my-5", "markdown-body");
Expand Down

0 comments on commit 2d92d85

Please sign in to comment.