mirror of
https://github.com/praktimarc/kst4contest.git
synced 2026-07-13 16:16:44 +02:00
Generate manual overviews from github_docs
This commit is contained in:
@@ -1,6 +1,59 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const markdownIt = require("markdown-it");
|
||||
const markdownItAnchor = require("markdown-it-anchor");
|
||||
|
||||
module.exports = function (eleventyConfig) {
|
||||
eleventyConfig.addPassthroughCopy({ "src/assets": "assets" });
|
||||
|
||||
const md = markdownIt({
|
||||
html: true,
|
||||
linkify: true,
|
||||
typographer: true
|
||||
}).use(markdownItAnchor, {
|
||||
permalink: markdownItAnchor.permalink.headerLink()
|
||||
});
|
||||
|
||||
eleventyConfig.addFilter("markdown", function (value) {
|
||||
return md.render(value || "");
|
||||
});
|
||||
|
||||
eleventyConfig.addCollection("manualPages", function () {
|
||||
const docsDir = path.join(__dirname, "..", "github_docs");
|
||||
|
||||
if (!fs.existsSync(docsDir)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return fs.readdirSync(docsDir)
|
||||
.filter(file => /^(en|de)-.+\.md$/.test(file))
|
||||
.map(file => {
|
||||
const fullPath = path.join(docsDir, file);
|
||||
const raw = fs.readFileSync(fullPath, "utf8");
|
||||
|
||||
const lang = file.startsWith("de-") ? "de" : "en";
|
||||
const slug = file
|
||||
.replace(/^en-/, "")
|
||||
.replace(/^de-/, "")
|
||||
.replace(/\.md$/, "")
|
||||
.toLowerCase();
|
||||
|
||||
const title = file
|
||||
.replace(/^en-/, "")
|
||||
.replace(/^de-/, "")
|
||||
.replace(/\.md$/, "")
|
||||
.replace(/-/g, " ");
|
||||
|
||||
return {
|
||||
file,
|
||||
lang,
|
||||
slug,
|
||||
title,
|
||||
content: raw
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
dir: {
|
||||
input: "src",
|
||||
|
||||
Reference in New Issue
Block a user