-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
53 lines (43 loc) · 1.34 KB
/
.eleventy.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
const markdownIt = require("markdown-it");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const buildShaderList = require("./scripts/build-shader-list");
const fs = require('fs');
const shaderListOutPath = './page/_data/shaderList.json';
const highlightLanguage = {
"es3.glsl": "glsl",
"msl": "cpp",
}
function updateShaderList() {
console.log('Rebuilding shader list...');
fs.writeFileSync(shaderListOutPath, buildShaderList());
}
updateShaderList();
const fileRegex = /\/\/\s*@file\s*:\s*([a-zA-Z0-9\s]*)/g;
module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addPassthroughCopy('./page/assets');
const md = new markdownIt({ html: true });
eleventyConfig.addPairedShortcode("shader", (content, ext) => {
if (ext == 'md') {
return md.render(content);
}
output = syntaxHighlight.pairedShortcode(content, highlightLanguage[ext] ?? ext);
return output.replaceAll(fileRegex, '<h4>$1</h4>');
});
eleventyConfig.addWatchTarget("./shaders");
eleventyConfig.on('eleventy.beforeWatch', async (changedFiles) => {
for (file of changedFiles) {
console.log(file);
if (file.includes('./shaders/')) {
updateShaderList();
return;
}
}
});
return {
dir: {
input: "page",
output: "_site",
}
}
};