2022-01-24 16:11:14 +00:00
|
|
|
const pluginNavigation = require("@11ty/eleventy-navigation");
|
|
|
|
const markdownItAttrs = require("markdown-it-attrs");
|
2022-01-24 16:21:14 +00:00
|
|
|
const autoprefixer = require("autoprefixer");
|
2022-01-24 16:11:14 +00:00
|
|
|
const markdownIt = require("markdown-it");
|
|
|
|
const htmlmin = require("html-minifier");
|
2022-01-24 18:01:01 +00:00
|
|
|
const purgecss = require("purgecss");
|
2022-01-24 16:21:14 +00:00
|
|
|
const postcss = require("postcss");
|
2022-01-22 08:31:25 +00:00
|
|
|
const yaml = require("js-yaml");
|
2022-01-24 16:21:14 +00:00
|
|
|
const path = require("path");
|
2022-01-24 16:11:14 +00:00
|
|
|
const sass = require("sass");
|
|
|
|
const fs = require("fs");
|
|
|
|
const markdownLib = markdownIt({
|
2021-10-07 20:45:46 +00:00
|
|
|
html: true,
|
|
|
|
breaks: true,
|
2022-01-24 16:11:14 +00:00
|
|
|
linkify: true,
|
|
|
|
}).use(markdownItAttrs);
|
2022-01-22 08:31:25 +00:00
|
|
|
|
2022-01-24 18:01:01 +00:00
|
|
|
const pattern = new RegExp("(<style>)(.*)?(</style>)", "gm");
|
|
|
|
|
2021-05-20 20:02:50 +00:00
|
|
|
module.exports = function (eleventyConfig) {
|
2022-01-24 16:11:14 +00:00
|
|
|
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({
|
2022-01-24 16:11:14 +00:00
|
|
|
"assets/": "./",
|
|
|
|
});
|
|
|
|
|
2022-01-24 16:21:14 +00:00
|
|
|
eleventyConfig.on("eleventy.before", async () => {
|
2022-01-24 18:06:15 +00:00
|
|
|
// iterate over scss files
|
2022-01-24 16:11:14 +00:00
|
|
|
let files = fs.readdirSync("./src/scss/");
|
|
|
|
files.forEach((file) => {
|
|
|
|
// Compile SASS
|
2022-01-24 16:21:14 +00:00
|
|
|
const result = sass.compile("./src/scss/".concat(file), {
|
2022-01-24 16:11:14 +00:00
|
|
|
style: "compressed",
|
|
|
|
sourceMap: false,
|
|
|
|
});
|
|
|
|
console.log(`[SCSS] ${file} compiled`);
|
2022-01-24 16:21:14 +00:00
|
|
|
|
|
|
|
// Optimize and write file with PostCSS
|
|
|
|
postcss([autoprefixer])
|
|
|
|
.process(result.css.toString())
|
|
|
|
.then((result) => {
|
|
|
|
fs.writeFile(
|
|
|
|
"./src/_includes/css/".concat(path.parse(file).name, ".css"),
|
|
|
|
result.css,
|
|
|
|
(err) => {
|
|
|
|
if (err) throw err;
|
|
|
|
console.log(`[POSTCSS] ${file} optimized`);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2022-01-24 16:11:14 +00:00
|
|
|
});
|
|
|
|
});
|
2020-11-19 15:00:39 +00:00
|
|
|
|
2022-01-24 16:11:14 +00:00
|
|
|
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
|
|
|
|
2022-01-24 18:01:01 +00:00
|
|
|
eleventyConfig.addTransform(
|
|
|
|
"purgestyle",
|
|
|
|
async function (content, outputPath) {
|
|
|
|
if (
|
|
|
|
process.env.NODE_ENV === "production" &&
|
|
|
|
outputPath &&
|
|
|
|
outputPath.endsWith(".html")
|
|
|
|
) {
|
|
|
|
const [{ css: result }] = await new purgecss.PurgeCSS().purge({
|
|
|
|
content: [
|
|
|
|
{ raw: content.replace(pattern, "$1$3"), extension: "html" },
|
|
|
|
],
|
|
|
|
css: [{ raw: pattern.exec(content)[2] }],
|
|
|
|
});
|
|
|
|
console.log(`[PURGECSS] ${outputPath} purged`);
|
|
|
|
return content.replace(pattern, `<style>${result}</style>`);
|
|
|
|
}
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2022-01-24 16:11:14 +00:00
|
|
|
eleventyConfig.addShortcode("year", () => {
|
|
|
|
const year = new Date().getFullYear();
|
|
|
|
return year.toString();
|
|
|
|
});
|
2021-05-20 20:02:50 +00:00
|
|
|
|
|
|
|
return {
|
2022-01-24 16:11:14 +00:00
|
|
|
markdownTemplateEngine: "njk",
|
2021-10-07 20:45:46 +00:00
|
|
|
passthroughFileCopy: true,
|
2021-05-20 20:02:50 +00:00
|
|
|
dir: {
|
2022-01-24 16:11:14 +00:00
|
|
|
includes: "_includes",
|
|
|
|
output: "_site",
|
|
|
|
data: "_data",
|
|
|
|
input: "src",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|