Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build github.io pages with pandoc instead of Jekyll #248

Merged
merged 31 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7c11b51
Build with pandoc
HeikoTheissen Apr 8, 2024
a9638a4
relative paths
HeikoTheissen Apr 9, 2024
bf867dd
style.css
HeikoTheissen Apr 9, 2024
a6716db
Titles
HeikoTheissen Apr 9, 2024
c73bf30
index.html
HeikoTheissen Apr 9, 2024
108ec7e
Better titles
HeikoTheissen Apr 9, 2024
3aebc1c
absolute stylesheet path
HeikoTheissen Apr 9, 2024
a0dc7c4
.md instead of .html
HeikoTheissen Apr 9, 2024
843afe6
Rewrite links .md -> .html
HeikoTheissen Apr 9, 2024
ab2cfad
htmlOutput flag
HeikoTheissen Apr 9, 2024
b544a73
clean up
HeikoTheissen Apr 9, 2024
e62f0ce
Use pandoc-filter to rewrite links
HeikoTheissen Apr 9, 2024
2d98843
npm ci
HeikoTheissen Apr 9, 2024
9c2b3d1
README.html -> index.html
HeikoTheissen Apr 9, 2024
d1f1524
remove superfluous parameter
HeikoTheissen Apr 9, 2024
9db308f
repo name as title
HeikoTheissen Apr 10, 2024
2d92d85
Allow dynamic URLs
HeikoTheissen Apr 10, 2024
0229311
Dynamic URLs with Jekyll syntax
HeikoTheissen Apr 10, 2024
be01d17
Even better titles
HeikoTheissen Apr 10, 2024
9bc77f8
double -> single quotes
HeikoTheissen Apr 10, 2024
3574b3c
Titles with spaces
HeikoTheissen Apr 10, 2024
32c7d89
Use a pandoc template
HeikoTheissen Apr 10, 2024
6373ca0
Header in <div>
HeikoTheissen Apr 10, 2024
34d0a98
Take template from current repo
HeikoTheissen Apr 10, 2024
b05c3d0
Allow template overriding
HeikoTheissen Apr 10, 2024
aa429f1
Prepare for cross-repo reuse
HeikoTheissen Apr 10, 2024
59fe20d
export pandoc template
HeikoTheissen Apr 10, 2024
9460ed1
+test case
HeikoTheissen Apr 10, 2024
fb7a127
Test needs pandoc
HeikoTheissen Apr 10, 2024
bbdc2f4
typo
HeikoTheissen Apr 10, 2024
18c8542
Expensive pandoc test runs only locally
HeikoTheissen Apr 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Sample workflow for building and deploying a Jekyll site to GitHub Pages
name: Build GitHub Pages using pandoc

on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
# Build job
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Setup pandoc
uses: nikeee/setup-pandoc@v1
with:
pandoc-version: 3.1.12.2
- name: Build with pandoc
run: |
npm ci
npm run pages "OASIS OData TC"
- name: Upload artifact
uses: actions/upload-pages-artifact@v3

# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: |
npm ci
npm run build --if-present
npm test
npm test test/csdl2markdown.test.js
git diff --exit-code vocabularies
env:
CI: true
1 change: 1 addition & 0 deletions assets/styles/style.css

Large diffs are not rendered by default.

78 changes: 78 additions & 0 deletions assets/template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="$lang$" xml:lang="$lang$"$if(dir)$ dir="$dir$"$endif$>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
$for(author-meta)$
<meta name="author" content="$author-meta$" />
$endfor$
$if(date-meta)$
<meta name="dcterms.date" content="$date-meta$" />
$endif$
$if(keywords)$
<meta name="keywords" content="$for(keywords)$$keywords$$sep$, $endfor$" />
$endif$
$if(description-meta)$
<meta name="description" content="$description-meta$" />
$endif$
<title>$if(title-prefix)$$title-prefix$ – $endif$$pagetitle$</title>
<style>
$styles.html()$
</style>
$for(css)$
<link rel="stylesheet" href="$css$" />
$endfor$
$for(header-includes)$
$header-includes$
$endfor$
$if(math)$
$if(mathjax)$
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
$endif$
$math$
$endif$
</head>
<body>
$for(include-before)$
$include-before$
$endfor$
<div class="container-lg px-3 my-5 markdown-body">
$if(title)$
<header id="title-block-header">
<h1 class="title">$title$</h1>
$if(subtitle)$
<p class="subtitle">$subtitle$</p>
$endif$
$for(author)$
<p class="author">$author$</p>
$endfor$
$if(date)$
<p class="date">$date$</p>
$endif$
$if(abstract)$
<div class="abstract">
<div class="abstract-title">$abstract-title$</div>
$abstract$
</div>
$endif$
</header>
$endif$
$if(toc)$
<nav id="$idprefix$TOC" role="doc-toc">
$if(toc-title)$
<h2 id="$idprefix$toc-title">$toc-title$</h2>
$endif$
$table-of-contents$
</nav>
$endif$
$body$
</div>
$for(include-after)$
$include-after$
$endfor$
$for(include-script)$
$include-script$
$endfor$
</body>
</html>
10 changes: 10 additions & 0 deletions lib/md2html.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env node

const filter = require("pandoc-filter");

filter.stdio(function ({ t, c }, format, meta) {
if (t === "Link" && !/^https?:\/\//.test(c[2][0])) {
c[2][0] = c[2][0].replace(/\.md(?=$|#)/, ".html");
return filter.Link(...c);
}
});
45 changes: 45 additions & 0 deletions lib/pages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const pandoc = require("./pandoc");
const fs = require("fs");

const VOCAB = require("../package.json").name;
const REPO = process.argv[process.argv.length - 1];

function file(dir, title, filename) {
console.log(`${dir}/${filename}`);
pandoc(
{
stdin: fs.createReadStream(`${__dirname}/../${dir}/${filename}`),
stdout: fs.createWriteStream(
`_site/${dir}/${filename === "README.md" ? "index.html" : filename.replace(/\.md$/, ".html")}`,
),
},
{
"-c": `/${VOCAB}/styles/style.css`,
"-F": `${__dirname}/md2html.js`,
"-M": `title=${REPO}${title ? " - " + title : ""}`,
"--template": "assets/template",
},
);
}

function directory(dir, title) {
if (fs.existsSync(`${__dirname}/../${dir}`)) {
fs.cpSync(`${__dirname}/../${dir}`, `_site/${dir}`, {
recursive: true,
});
fs.readdirSync(`${__dirname}/../${dir}`)
.filter((fn) => fn.endsWith(".md"))
.forEach(function (filename) {
file(dir, title, filename);
});
}
}

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

file(".", "", "README.md");
directory("docs", "Documents");
directory("examples", "Examples");
directory("vocabularies", "Vocabularies");
41 changes: 41 additions & 0 deletions lib/pandoc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const { spawn } = require("child_process");

function pandoc({ stdin, stdout }, options = {}) {
var mermaidOptions = { startOnLoad: false, ...options.mermaid };
delete options.mermaid;
var opts = [
"-f",
"gfm+tex_math_dollars",
"-t",
"html",
"--mathjax",
"-s",
"--eol=lf",
"--wrap=none",
"-V",
`include-script=<script type="module">
document.addEventListener("DOMContentLoaded", function() {
document.querySelectorAll(".mermaid").forEach(function(pre) {
pre.style.width = pre.getClientRects()[0].width + "px";
});
});
import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs";
mermaid.initialize(${JSON.stringify(mermaidOptions)});
mermaid.run({nodes: document.querySelectorAll(".mermaid code")});
</script>`,
];
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());
});
proc.stdout.pipe(stdout);
stdin.on("error", console.error).pipe(proc.stdin);
}

module.exports = pandoc;
22 changes: 21 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@
"bin": {
"odata-vocab2md": "lib/cli.js"
},
"main": "lib/csdl2markdown.js",
"exports": {
".": "./lib/csdl2markdown.js",
"./pandoc": "./lib/pandoc.js",
"./pages": "./lib/pages.js",
"./template": "./assets/template.html"
},
"dependencies": {
"colors": "^1.4.0",
"odata-csdl": "^0.9.5"
"odata-csdl": "^0.9.5",
"pandoc-filter": "^2.2.0"
},
"devDependencies": {
"c8": "^9.1.0",
Expand All @@ -26,6 +32,7 @@
},
"scripts": {
"build": "node lib/transform.js",
"pages": "node lib/pages.js",
"test": "c8 -r html -r text mocha",
"watch": "mocha --watch"
},
Expand Down
34 changes: 34 additions & 0 deletions test/pandoc.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const assert = require("assert");
const fs = require("fs");
const pandoc = require("../lib/pandoc");
const { PassThrough } = require("stream");

describe("OASIS voc build", function () {
it("Pandoc", function () {
var html = "";
pandoc(
{
stdin: fs.createReadStream(`${__dirname}/test-data/pandoc.md`),
stdout: new PassThrough()
.on("data", function (chunk) {
html += chunk.toString();
})
.on("end", function () {
assert.deepStrictEqual(
html.split(/\r\n|\r|\n/),
fs
.readFileSync(`${__dirname}/test-data/pandoc.html`)
.toString()
.split(/\r\n|\r|\n/),
);
}),
},
{
"-c": "style.css",
"-F": `${__dirname}/../lib/md2html.js`,
"-M": "title=Test",
"--template": `${__dirname}/../assets/template`,
},
);
});
});
Loading