Skip to content

Commit

Permalink
Upgrade to eleventy 1.0 🎉 (google#111)
Browse files Browse the repository at this point in the history
## Trivial

`s/slug/slugify`

## Changes

- More robust test triggering (Now gets triggered by test changes or by the build actually finishing)
- Fixed bad tests for draft posts.

## Not so great

Changed the `addHash` filter to read from source directories instead of `_site`. This works but it would not work if a file would be synthesized into the output dir. This is necessary due to a race condition that only happens in `watch` mode where `_site` doesn't exist during re-build.
  • Loading branch information
cramforce authored Jan 22, 2022
1 parent 377c7f7 commit 3468afe
Show file tree
Hide file tree
Showing 8 changed files with 928 additions and 983 deletions.
20 changes: 18 additions & 2 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@
const { DateTime } = require("luxon");
const { promisify } = require("util");
const fs = require("fs");
const path = require("path");
const hasha = require("hasha");
const touch = require("touch");
const readFile = promisify(fs.readFile);
const readdir = promisify(fs.readdir);
const stat = promisify(fs.stat);
const execFile = promisify(require("child_process").execFile);
const pluginRss = require("@11ty/eleventy-plugin-rss");
Expand Down Expand Up @@ -79,7 +82,7 @@ module.exports = function (eleventyConfig) {
eleventyConfig.addNunjucksAsyncFilter(
"addHash",
function (absolutePath, callback) {
readFile(`_site${absolutePath}`, {
readFile(path.join(".", absolutePath), {
encoding: "utf-8",
})
.then((content) => {
Expand All @@ -88,7 +91,11 @@ module.exports = function (eleventyConfig) {
.then((hash) => {
callback(null, `${absolutePath}?hash=${hash.substr(0, 10)}`);
})
.catch((error) => callback(error));
.catch((error) => {
callback(
new Error(`Failed to addHash to '${absolutePath}': ${error}`)
);
});
}
);

Expand Down Expand Up @@ -228,6 +235,15 @@ module.exports = function (eleventyConfig) {
}
});

// After the build touch any file in the test directory to do a test run.
eleventyConfig.on("afterBuild", async () => {
const files = await readdir("test");
for (const file of files) {
touch(`test/${file}`);
break;
}
});

return {
templateFormats: ["md", "njk", "html", "liquid"],

Expand Down
2 changes: 1 addition & 1 deletion _data/isdevelopment.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@

module.exports = function () {
// YOLO.
return /serve/.test(process.argv.join());
return /serve|watch/.test(process.argv.join());
};
Loading

0 comments on commit 3468afe

Please sign in to comment.