This repository has been archived on 2023-03-14. You can view files and clone it, but cannot push or open issues or pull requests.
personal-website-old/.eleventy.js

72 lines
1.9 KiB
JavaScript
Raw Normal View History

const pluginNavigation = require("@11ty/eleventy-navigation");
const markdownItAttrs = require("markdown-it-attrs");
const markdownIt = require("markdown-it");
const htmlmin = require("html-minifier");
2022-01-22 08:31:25 +00:00
const yaml = require("js-yaml");
const sass = require("sass");
const fs = require("fs");
const markdownLib = markdownIt({
2021-10-07 20:45:46 +00:00
html: true,
breaks: true,
linkify: true,
}).use(markdownItAttrs);
2022-01-22 08:31:25 +00:00
2021-05-20 20:02:50 +00:00
module.exports = function (eleventyConfig) {
eleventyConfig.addDataExtension("yml", (contents) => yaml.load(contents));
eleventyConfig.addGlobalData("username", "Laureηt");
eleventyConfig.addWatchTarget("./src/scss/");
eleventyConfig.setLibrary("md", markdownLib);
eleventyConfig.addPlugin(pluginNavigation);
eleventyConfig.setUseGitIgnore(false);
2021-05-20 20:02:50 +00:00
eleventyConfig.addPassthroughCopy({
"assets/": "./",
});
eleventyConfig.on("eleventy.before", () => {
let files = fs.readdirSync("./src/scss/");
files.forEach((file) => {
// Compile SASS
let result = sass.compile("./src/scss/".concat(file), {
style: "compressed",
sourceMap: false,
});
console.log(`[SCSS] ${file} compiled`);
});
});
eleventyConfig.addTransform("htmlmin", function (content, outputPath) {
if (
process.env.NODE_ENV === "production" &&
outputPath &&
outputPath.endsWith(".html")
) {
const minified = htmlmin.minify(content, {
collapseWhitespace: true,
useShortDoctype: true,
removeComments: true,
minifyCSS: true,
minifyJS: true,
});
return minified;
} else {
return content;
}
});
2021-10-07 16:31:51 +00:00
eleventyConfig.addShortcode("year", () => {
const year = new Date().getFullYear();
return year.toString();
});
2021-05-20 20:02:50 +00:00
return {
markdownTemplateEngine: "njk",
2021-10-07 20:45:46 +00:00
passthroughFileCopy: true,
2021-05-20 20:02:50 +00:00
dir: {
includes: "_includes",
output: "_site",
data: "_data",
input: "src",
},
};
};