2023-11-05 23:05:38 +08:00
|
|
|
const { DateTime } = require("luxon");
|
|
|
|
const CleanCSS = require("clean-css");
|
|
|
|
const htmlmin = require("html-minifier");
|
|
|
|
const markdownIt = require("markdown-it");
|
|
|
|
const markdownItAttrs = require("markdown-it-attrs");
|
2023-12-16 12:20:33 +08:00
|
|
|
const markdownItAnchor = require("markdown-it-anchor");
|
2023-11-05 23:05:38 +08:00
|
|
|
|
|
|
|
module.exports = function(eleventyConfig) {
|
|
|
|
|
|
|
|
eleventyConfig.setUseGitIgnore(false);
|
|
|
|
|
|
|
|
const mdOptions = {
|
|
|
|
html: true,
|
|
|
|
breaks: true,
|
|
|
|
linkify: true,
|
|
|
|
};
|
|
|
|
|
2023-12-16 12:20:33 +08:00
|
|
|
const markdownItAnchorOptions = {
|
|
|
|
level: 2, // minimum level header -- anchors will only be applied to h2 level headers and below but not h1
|
|
|
|
permalink: true,
|
|
|
|
}
|
|
|
|
|
2023-11-05 23:05:38 +08:00
|
|
|
const markdownLib = markdownIt(mdOptions)
|
2023-12-16 12:20:33 +08:00
|
|
|
.use(markdownItAnchor,markdownItAnchorOptions)
|
2023-11-05 23:05:38 +08:00
|
|
|
.use(markdownItAttrs)
|
|
|
|
.use(require('markdown-it-bracketed-spans'))
|
|
|
|
.disable("code");
|
|
|
|
|
|
|
|
eleventyConfig.setLibrary("md", markdownLib);
|
|
|
|
|
|
|
|
eleventyConfig.setTemplateFormats([
|
|
|
|
"md",
|
|
|
|
"webmanifest",
|
|
|
|
"xml",
|
|
|
|
"ico",
|
|
|
|
"svg",
|
|
|
|
"png",
|
|
|
|
"jpg",
|
|
|
|
"txt",
|
|
|
|
"woff",
|
|
|
|
"woff2",
|
|
|
|
"css",
|
|
|
|
"pdf"
|
2023-12-16 12:20:33 +08:00
|
|
|
]);
|
|
|
|
|
2023-11-05 23:05:38 +08:00
|
|
|
eleventyConfig.addFilter("readablePostDate", (dateObj) => {
|
|
|
|
return DateTime.fromJSDate(dateObj, {
|
2023-11-07 07:40:08 +08:00
|
|
|
zone: "Asia/Singapore",
|
2023-11-05 23:05:38 +08:00
|
|
|
}).setLocale('en-GB').toLocaleString({day: 'numeric',month: 'short',year: 'numeric'});
|
|
|
|
});
|
|
|
|
|
|
|
|
eleventyConfig.addFilter("postDate", (dateObj) => {
|
|
|
|
return DateTime.fromJSDate(dateObj, {
|
|
|
|
zone: "Asia/Singapore",
|
|
|
|
}).setLocale('en-GB').toISODate();
|
|
|
|
});
|
2023-12-16 12:20:33 +08:00
|
|
|
|
2023-11-05 23:05:38 +08:00
|
|
|
eleventyConfig.addTransform("htmlmin", function(content, outputPath) {
|
|
|
|
if( outputPath && outputPath.endsWith(".html") ) {
|
|
|
|
let minified = htmlmin.minify(content, {
|
|
|
|
useShortDoctype: true,
|
|
|
|
removeComments: true,
|
|
|
|
collapseWhitespace: true
|
|
|
|
});
|
|
|
|
return minified;
|
|
|
|
}
|
|
|
|
return content;
|
2023-12-16 12:20:33 +08:00
|
|
|
});
|
|
|
|
|
2023-11-05 23:05:38 +08:00
|
|
|
return {
|
|
|
|
dir: {
|
|
|
|
input: "src",
|
|
|
|
includes: "_includes",
|
|
|
|
output: "site"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
eleventyConfig.addPassthroughCopy('/src/css')
|
|
|
|
return {
|
|
|
|
passthroughFileCopy: true
|
|
|
|
}
|
2023-12-16 12:20:33 +08:00
|
|
|
};
|