forked from fluid-project/infusion-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eleventy.config.js
93 lines (79 loc) · 3.48 KB
/
eleventy.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
Copyright 2014-2024 OCAD University
Copyright 2017 Raising the Floor, International
Licensed under the Educational Community License (ECL), Version 2.0 or the New
BSD license. You may not use this file except in compliance with one these
Licenses.`
You may obtain a copy of the ECL 2.0 License and BSD License at
https://github.com/fluid-project/infusion/raw/main/Infusion-LICENSE.txt
*/
"use strict";
var githubSlugify = require("github-slugger").slug;
var {exec} = require("child_process");
const brokenLinksPlugin = require("eleventy-plugin-broken-links");
require("./index.js");
var hljs = require("highlight.js");
var parseTransform = require("./src/transforms/parse.js");
var navigationPlugin = require("@11ty/eleventy-navigation");
module.exports = function (eleventyConfig) {
var markdownit = require("markdown-it")({
html: true,
highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang)) {
try {
return "<pre class=\"highlight\"><code class=\"hljs " + lang + "\">" +
hljs.highlight(str, {language: lang, ignoreIllegals: true}).value +
"</code></pre>";
} catch (__) {}
}
return "<pre class=\"highlight\"><code class=\"hljs " + lang + "\">" + markdownit.utils.escapeHtml(str) + "</code></pre>";
}
});
var markdownItAnchor = require("markdown-it-anchor");
var markdownItLibrary = markdownit.use(markdownItAnchor, { slugify: githubSlugify });
eleventyConfig.setLibrary("md", markdownItLibrary);
eleventyConfig.addTransform("parse", parseTransform);
eleventyConfig.addPlugin(navigationPlugin);
eleventyConfig.addPlugin(brokenLinksPlugin, {
forbidden: "error",
broken: "error",
// Codepen links return 403
// see: https://github.com/bradleyburgess/eleventy-plugin-broken-links/issues/9
excludeUrls: ["https://codepen.io*"]
});
eleventyConfig.addPassthroughCopy({
"node_modules/infusion/dist": "lib/infusion/dist",
"node_modules/infusion/src": "lib/infusion/src",
"node_modules/foundation-sites/css": "lib/foundation",
"node_modules/octicons/octicons": "lib/octicons",
"src/static/css": "css",
"src/static/fonts": "fonts",
"src/static/images": "images",
"src/static/js": "js",
"src/scripts": "js",
"src/documents/images": "images",
"src/icons": "/"
});
// Helper function to rewrite *.md links to *.html:
// With this helper, we can write links to *.md files in our source files but
// generate links to *.html in the DocPad output. This arrangement gives us
// links that work both on the GitHub website and in the generated HTML.
eleventyConfig.addFilter("rewriteMdLinks", function (content) {
return content.replace(/(<a\s[^>]*href="[\w-/\.]+)\.md(["#])/gm, "$1.html$2");
});
// Helper function to add a prefix to a relative URL.
eleventyConfig.addFilter("addPrefix", function (href) {
return "/infusion/development" + href;
});
eleventyConfig.on("afterBuild", async () => {
// TODO: Once 11ty v3 is stable and the project updated to use it, it will be possible to use Pagefind's
// NodeJS API instead of calling `npx` with `exec`. This is because 11ty currently doesn't support ES6 modules.
// https://pagefind.app/docs/node-api/
await exec("npx pagefind");
});
return {
dir: {
input: "src"
}
};
};