Skip to content

Commit c827b11

Browse files
authored
Eleventy v2.0.0 and March 2023 Updates (#81)
- Eleventy v2.0.0 - Use a plugin for generating the sitemap - Add March 2023 event - Run CI on Node 18
1 parent 6e12918 commit c827b11

File tree

8 files changed

+630
-5811
lines changed

8 files changed

+630
-5811
lines changed

.eleventy.js

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
const fs = require('fs');
1+
const fs = require('node:fs');
22
const inclusiveLangPlugin = require('@11ty/eleventy-plugin-inclusive-language');
33
const cacheBuster = require('@mightyplow/eleventy-plugin-cache-buster');
4+
const pluginSitemap = require('@quasibit/eleventy-plugin-sitemap');
45
const htmlmin = require('html-minifier');
56
const { minify } = require('terser');
67
const siteSettings = require('./src/globals/site.json');
@@ -16,7 +17,15 @@ const dateFormatter = Intl.DateTimeFormat('en-US', {
1617
});
1718

1819
module.exports = function (eleventyConfig) {
19-
eleventyConfig.addPassthroughCopy('./src/css/tailwind.include.css');
20+
const runMode = process.env.ELEVENTY_RUN_MODE;
21+
const isProduction = runMode === 'build';
22+
23+
eleventyConfig.addPlugin(pluginSitemap, {
24+
sitemap: {
25+
hostname: siteSettings.url,
26+
},
27+
});
28+
2029
eleventyConfig.addPassthroughCopy({ public: './' });
2130

2231
eleventyConfig.addShortcode('year', function () {
@@ -29,7 +38,7 @@ module.exports = function (eleventyConfig) {
2938

3039
eleventyConfig.addPlugin(inclusiveLangPlugin);
3140

32-
if (process.env.ELEVENTY_ENV === 'production') {
41+
if (isProduction) {
3342
eleventyConfig.addPlugin(cacheBuster({ outputDirectory: 'dist' }));
3443

3544
eleventyConfig.addTransform('htmlmin', function (content, outputPath) {
@@ -45,37 +54,19 @@ module.exports = function (eleventyConfig) {
4554
});
4655
}
4756

48-
eleventyConfig.addNunjucksAsyncFilter(
49-
'jsmin',
50-
async function (code, callback) {
51-
if (process.env.ELEVENTY_ENV === 'production') {
52-
try {
53-
const minified = await minify(code);
54-
callback(null, minified.code);
55-
} catch (err) {
56-
console.error('Terser error: ', err);
57-
// Fail gracefully.
58-
callback(null, code);
59-
}
60-
} else {
61-
callback(null, code);
57+
eleventyConfig.addAsyncFilter('jsmin', async function (code) {
58+
if (isProduction) {
59+
try {
60+
const minified = await minify(code);
61+
return minified.code;
62+
} catch (err) {
63+
console.error('Terser error: ', err);
64+
// Fail gracefully.
65+
return code;
6266
}
67+
} else {
68+
return code;
6369
}
64-
);
65-
66-
eleventyConfig.setBrowserSyncConfig({
67-
callbacks: {
68-
ready: function (err, bs) {
69-
bs.addMiddleware('*', (req, res) => {
70-
const content_404 = fs.readFileSync('dist/404.html');
71-
// Provides the 404 content without redirect.
72-
res.write(content_404);
73-
// Add 404 http status code in request header.
74-
res.writeHead(404, { 'Content-Type': 'text/html' });
75-
res.end();
76-
});
77-
},
78-
},
7970
});
8071

8172
return {

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- name: Setup node
1111
uses: actions/setup-node@v3
1212
with:
13-
node-version: '16.x'
13+
node-version: '18.x'
1414
- name: Install dependencies
1515
run: npm ci
1616
- name: Build site

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- name: Setup node
1212
uses: actions/setup-node@v3
1313
with:
14-
node-version: '16.x'
14+
node-version: '18.x'
1515
- name: Install dependencies
1616
run: npm ci
1717
- name: Build site

0 commit comments

Comments
 (0)