0
0
website/.eleventy.js

102 lines
3.0 KiB
JavaScript
Raw Normal View History

2023-11-05 23:05:38 +08:00
const { DateTime } = require("luxon");
2024-10-16 12:39:17 +08:00
//const CleanCSS = require("clean-css");
const { minify } = require("html-minifier-terser");
2023-11-05 23:05:38 +08:00
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
2024-10-16 12:39:17 +08:00
module.exports = function (eleventyConfig) {
eleventyConfig.setUseGitIgnore(false);
2023-11-05 23:05:38 +08:00
2024-10-16 12:39:17 +08:00
const mdOptions = {
html: true,
breaks: true,
linkify: true,
};
2023-11-05 23:05:38 +08:00
2024-10-16 12:39:17 +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
2024-10-16 12:39:17 +08:00
const markdownLib = markdownIt(mdOptions)
.use(markdownItAnchor, markdownItAnchorOptions)
.use(markdownItAttrs)
.use(require("markdown-it-bracketed-spans"))
.disable("code");
2023-11-05 23:05:38 +08:00
2024-10-16 12:39:17 +08:00
eleventyConfig.setLibrary("md", markdownLib);
2023-11-05 23:05:38 +08:00
2024-10-16 12:39:17 +08:00
eleventyConfig.setTemplateFormats([
"md",
"webmanifest",
"xml",
"ico",
"avif",
"webp",
"webm",
"svg",
"png",
"jpg",
"jpeg",
"txt",
"woff",
"woff2",
"css",
"pdf",
]);
2023-12-16 12:20:33 +08:00
2024-10-16 12:39:17 +08:00
eleventyConfig.addFilter("readablePostDate", (dateObj) => {
return DateTime.fromJSDate(dateObj, {
zone: "Asia/Singapore",
})
.setLocale("en-GB")
.toLocaleString({ day: "numeric", month: "short", year: "numeric" });
});
2023-11-05 23:05:38 +08:00
2024-10-16 12:39:17 +08:00
eleventyConfig.addFilter("postDate", (dateObj) => {
return DateTime.fromJSDate(dateObj, {
zone: "Asia/Singapore",
})
.setLocale("en-GB")
.toISODate();
});
2023-12-16 12:20:33 +08:00
2024-10-16 12:39:17 +08:00
eleventyConfig.addTransform("minifyHTML", function (content, outputPath) {
// Only minify HTML files
if (outputPath && outputPath.endsWith(".html")) {
return minify(content, {
collapseWhitespace: true, // Collapses whitespace between tags
removeComments: true, // Removes HTML comments
minifyCSS: true, // Minifies inline CSS
minifyJS: true, // Minifies inline JavaScript
removeAttributeQuotes: true, // Removes quotes around attributes when possible
removeOptionalTags: true, // Removes optional HTML tags (<html>, <head>, <body>)
collapseBooleanAttributes: true, // Converts boolean attributes to HTML5 style
removeEmptyAttributes: true, // Removes empty attributes
minifyURLs: true, // Minifies URLs in attributes
html5: true, // Enables HTML5 parsing
// caseSensitive: true, // Treats tags and attributes as case-sensitive
// keepClosingSlash: true, // Keeps trailing slash on self-closing tags
// quoteCharacter: '"', // Specifies quote character for attributes
// processConditionalComments: true, // Processes conditional comments in IE
// trimCustomFragments: true, // Trims custom HTML fragments
});
}
2023-11-05 23:05:38 +08:00
return content;
2024-10-16 12:39:17 +08:00
});
2023-12-16 12:20:33 +08:00
2024-10-16 12:39:17 +08:00
return {
dir: {
input: "src",
includes: "_includes",
output: "site",
},
};
2023-11-05 23:05:38 +08:00
2024-10-16 12:39:17 +08:00
eleventyConfig.addPassthroughCopy("/src/css");
return {
passthroughFileCopy: true,
};
2023-12-16 12:20:33 +08:00
};