From 979a4d56ae3d66208238dea2ddd43b3598d6a837 Mon Sep 17 00:00:00 2001 From: Malte Ubl Date: Thu, 1 Oct 2020 18:38:49 -0700 Subject: [PATCH 1/6] Shell out to git for a better last modified date --- .eleventy.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/.eleventy.js b/.eleventy.js index f68f173..b922096 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -89,9 +89,22 @@ module.exports = function (eleventyConfig) { .catch((error) => callback(error)); }); - eleventyConfig.addFilter("lastModifiedDate", function (filename) { - const stats = fs.statSync(filename); - return stats.mtime; // Date + eleventyConfig.addNunjucksAsyncFilter("lastModifiedDate", function ( + filename, + callback + ) { + require("child_process").execFile( + "git", + ["log", "-1", "--format=%cd", filename], + (error, stdout) => { + if (error) { + console.error(error); + const stats = fs.statSync(filename); + callback(null, stats.mtime); // Date + } + callback(null, new Date(stdout)); + } + ); }); eleventyConfig.addFilter("encodeURIComponent", function (str) { From 3cb86a025f26d552c712184945cf8a4e68373159 Mon Sep 17 00:00:00 2001 From: Malte Ubl Date: Thu, 1 Oct 2020 18:40:58 -0700 Subject: [PATCH 2/6] Avoid hardcoding image dimensions in test Fixes #42 --- test/test-generic-post.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test-generic-post.js b/test/test-generic-post.js index b01ed52..928f384 100644 --- a/test/test-generic-post.js +++ b/test/test-generic-post.js @@ -168,8 +168,8 @@ describe("check build output for a generic post", () => { //expect(avif.type).to.equal("image/avif"); expect(jpg.sizes).to.equal("(max-width: 608px) 100vw, 608px"); expect(webp.sizes).to.equal("(max-width: 608px) 100vw, 608px"); - expect(img.height).to.equal(850); - expect(img.width).to.equal(1280); + expect(img.height).to.match(/^\d+$/); + expect(img.width).to.match(/^\d+$/); expect(img.getAttribute("loading")).to.equal("lazy"); expect(img.getAttribute("decoding")).to.equal("async"); // JSDom fails to parse the style attribute properly From ab0cb0a63f0a2da0a23abb72a5516d867a6b8c9a Mon Sep 17 00:00:00 2001 From: Malte Ubl Date: Thu, 1 Oct 2020 19:57:25 -0700 Subject: [PATCH 3/6] Explicit liberal indexing --- _includes/layouts/base.njk | 1 + 1 file changed, 1 insertion(+) diff --git a/_includes/layouts/base.njk b/_includes/layouts/base.njk index 99ae89d..f0135b7 100644 --- a/_includes/layouts/base.njk +++ b/_includes/layouts/base.njk @@ -15,6 +15,7 @@ {% endif %} + {{ renderData.title or title or metadata.title | escape }} {% set desc = renderData.description or description %} From 5607091bceec56b89ddc4f9bc9a0cd339e1d67bc Mon Sep 17 00:00:00 2001 From: Bao Nguyen Date: Sat, 3 Oct 2020 23:05:47 +0800 Subject: [PATCH 4/6] Make updating the test "should have script elements" easier (#43) --- test/test-generic-post.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test-generic-post.js b/test/test-generic-post.js index 928f384..bd0fba0 100644 --- a/test/test-generic-post.js +++ b/test/test-generic-post.js @@ -63,7 +63,8 @@ describe("check build output for a generic post", () => { it("should have script elements", () => { const scripts = doc.querySelectorAll("script[src]"); - expect(scripts).to.have.length(GA_ID ? 2 : 1); + let has_ga_id = GA_ID ? 1 : 0; + expect(scripts).to.have.length(has_ga_id + 1); // NOTE: update this when adding more