116 lines
3.5 KiB
JavaScript
116 lines
3.5 KiB
JavaScript
import { inspect } from "util";
|
|
import browserslist from "browserslist";
|
|
import * as sass from "sass";
|
|
import path from "node:path";
|
|
import { bundle, browserslistToTargets, composeVisitors, transform } from "lightningcss" ;
|
|
import eleventyPDF from "./_config/eleventy-plugin-pdf.js";
|
|
|
|
export default async function (eleventyConfig) {
|
|
eleventyConfig.setUseGitIgnore(false);
|
|
|
|
eleventyConfig.addPassthroughCopy({"./src/_includes/js/" : "/js"});
|
|
|
|
eleventyConfig.addLayoutAlias('base', 'layouts/base.html');
|
|
eleventyConfig.addLayoutAlias('pdf', 'layouts/pdf.html');
|
|
|
|
eleventyConfig.addCollection("sections", (collectionApi) => {
|
|
const sections = collectionApi.getFilteredByGlob("./src/pages/sections/**")
|
|
.sort((a, b) => a.data.order - b.data.order);
|
|
process.env.DEBUG && console.log(inspect(sections));
|
|
return sections;
|
|
});
|
|
eleventyConfig.addCollection("projects", (collectionApi) => {
|
|
const projects = collectionApi.getFilteredByGlob("./src/projects/**")
|
|
.sort((a, b) => a.data.order - b.data.order);
|
|
process.env.DEBUG && console.log(inspect(projects));
|
|
return projects;
|
|
});
|
|
|
|
eleventyConfig.addCollection('experiences', collection => {
|
|
return [...collection.getFilteredByGlob('./src/experiences/*.md')]
|
|
.sort((a, b) => a.data.startDate - b.data.startDate).reverse();
|
|
});
|
|
|
|
eleventyConfig.addPlugin(eleventyPDF);
|
|
|
|
eleventyConfig.addPassthroughCopy('src/favicon.ico')
|
|
|
|
// Recognize CSS as a "template language"
|
|
eleventyConfig.addTemplateFormats("css");
|
|
|
|
// Process CSS with LightningCSS
|
|
eleventyConfig.addExtension("css", {
|
|
outputFileExtension: "css",
|
|
compile: async function (_inputContent, inputPath) {
|
|
let parsed = path.parse(inputPath);
|
|
if (parsed.name.startsWith("_")) {
|
|
return;
|
|
}
|
|
|
|
let targets = browserslistToTargets(browserslist("> 0.2% and not dead"));
|
|
|
|
return async () => {
|
|
// Switch to the `transform` function if you don't
|
|
// plan to use `@import` to merge files
|
|
let { code } = await bundle({
|
|
filename: inputPath,
|
|
minify: true,
|
|
sourceMap: false,
|
|
targets,
|
|
// Supports CSS nesting
|
|
drafts: {
|
|
nesting,
|
|
},
|
|
});
|
|
return code;
|
|
};
|
|
},
|
|
});
|
|
|
|
// Recognize Sass as a "template languages"
|
|
eleventyConfig.addTemplateFormats("scss");
|
|
|
|
// Compile Sass
|
|
eleventyConfig.addExtension("scss", {
|
|
outputFileExtension: "css",
|
|
compile: async function (inputContent, inputPath) {
|
|
// Skip files like _fileName.scss
|
|
let parsed = path.parse(inputPath);
|
|
if (parsed.name.startsWith("_")) {
|
|
return;
|
|
}
|
|
|
|
// Run file content through Sass
|
|
let result = sass.compileString(inputContent, {
|
|
loadPaths: [parsed.dir || "."],
|
|
sourceMap: false, // or true, your choice!
|
|
});
|
|
|
|
// Allow included files from @use or @import to
|
|
// trigger rebuilds when using --incremental
|
|
this.addDependencies(inputPath, result.loadedUrls);
|
|
|
|
let targets = browserslistToTargets(browserslist("> 0.2% and not dead"));
|
|
|
|
return async () => {
|
|
let { code } = await transform({
|
|
code: Buffer.from(result.css),
|
|
minify: true,
|
|
sourceMap: false,
|
|
targets,
|
|
});
|
|
return code;
|
|
};
|
|
},
|
|
});
|
|
|
|
return {
|
|
markdownTemplateEngine: 'liquid',
|
|
dataTemplateEngine: 'liquid',
|
|
htmlTemplateEngine: 'liquid',
|
|
dir: {
|
|
input: 'src',
|
|
output: 'dist'
|
|
}
|
|
};
|
|
}; |