Skip to content

Commit 149dc52

Browse files
committed
replace pug with nunjucks
1 parent 9347bb8 commit 149dc52

34 files changed

+482
-847
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist/
2+
node_modules/

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ repos:
55
- id: prettier
66
additional_dependencies:
77
- prettier
8-
- "@prettier/plugin-pug"
98

109
- repo: https://github.com/pre-commit/pre-commit-hooks
1110
rev: v6.0.0

eleventy.config.mjs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { minify } from "html-minifier";
2+
import sharp from "sharp";
3+
import path from "path";
4+
import fs from "fs";
5+
import { fileURLToPath } from "url";
6+
7+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
8+
9+
export default function (eleventyConfig) {
10+
// Exclude data helper modules from template processing
11+
eleventyConfig.ignores.add("src/pages/_helpers/**");
12+
13+
// Copy assets to output
14+
eleventyConfig.addPassthroughCopy({ "src/assets": "assets" });
15+
16+
// Watch content YAML files for changes
17+
eleventyConfig.addWatchTarget("src/content/");
18+
19+
// Minify HTML output
20+
eleventyConfig.addTransform("htmlmin", function (content, outputPath) {
21+
if (outputPath && outputPath.endsWith(".html")) {
22+
return minify(content, {
23+
removeComments: true,
24+
collapseWhitespace: true,
25+
});
26+
}
27+
return content;
28+
});
29+
30+
// Convert PNG images to WebP after build
31+
eleventyConfig.on("eleventy.after", async () => {
32+
const assetsDir = path.resolve(__dirname, "dist/assets");
33+
if (!fs.existsSync(assetsDir)) return;
34+
await convertPngsToWebp(assetsDir);
35+
});
36+
37+
return {
38+
dir: {
39+
input: "src/pages",
40+
output: "dist",
41+
},
42+
};
43+
}
44+
45+
async function convertPngsToWebp(dir) {
46+
const entries = fs.readdirSync(dir, { withFileTypes: true });
47+
for (const entry of entries) {
48+
const fullPath = path.join(dir, entry.name);
49+
if (entry.isDirectory()) {
50+
await convertPngsToWebp(fullPath);
51+
} else if (entry.name.endsWith(".png")) {
52+
const outFile = fullPath.replace(/\.png$/, ".webp");
53+
await sharp(fullPath).toFile(outFile);
54+
}
55+
}
56+
}

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
},
2222
"devDependencies": {
2323
"@11ty/eleventy": "3.0.0",
24-
"@11ty/eleventy-plugin-pug": "^1.0.0",
2524
"autoprefixer": "10.4.27",
2625
"concurrently": "9.2.1",
2726
"css-loader": "7.1.4",
@@ -30,7 +29,6 @@
3029
"mini-css-extract-plugin": "2.10.0",
3130
"postcss": "8.5.6",
3231
"postcss-loader": "8.2.1",
33-
"pug": "3.0.3",
3432
"sass": "1.97.3",
3533
"sass-loader": "16.0.7",
3634
"sharp": "0.34.5",

0 commit comments

Comments
 (0)