Skip to content

Commit ab8e85b

Browse files
authored
feat: add last updated date to blog posts (#692)
* feat: add last updated date to blog posts * move last updated to sidebar * use file system stats * revert * refactor * update blogDates.json * auto-stage blogDates.json * rename blogDates.json * update blog-dates.json * get staged files from command line * use path methods * rename script * update blog-dates.json * update blog-dates.json * update blog-dates.json * use published date for blog posts from August 2022 and earlier
1 parent 556f3dc commit ab8e85b

File tree

6 files changed

+599
-0
lines changed

6 files changed

+599
-0
lines changed

.eleventy.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const fs = require("node:fs");
2323
const yaml = require("js-yaml");
2424
const { DateTime } = require("luxon");
2525
const preWrapperPlugin = require("./src/_11ty/plugins/pre-wrapper.js");
26+
const blogDates = require("./src/_data/blog-dates.json");
2627

2728
//-----------------------------------------------------------------------------
2829
// Eleventy Config
@@ -160,6 +161,20 @@ module.exports = eleventyConfig => {
160161
value1.concat(value2),
161162
);
162163

164+
eleventyConfig.addFilter("lastUpdated", filepath => {
165+
const relativePath = path.relative("src/content/blog", filepath);
166+
const isoDate = blogDates[relativePath];
167+
const cutoffDate = new Date("2022-08-01");
168+
169+
if (!isoDate) {
170+
return null;
171+
}
172+
173+
const publishDate = new Date(relativePath.slice(0, 10));
174+
const date = new Date(isoDate);
175+
return publishDate > cutoffDate ? date : null;
176+
});
177+
163178
/**
164179
* ***************************************************************************************
165180
* Plugins

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"license": "Apache-2.0",
1616
"scripts": {
1717
"build": "npm-run-all install:playground build:sass build:website build:playground build:minify-images",
18+
"build:init-blog-dates": "node tools/update-blog-dates.js --init",
1819
"build:minify-images": "imagemin '_site/assets/images' --out-dir='_site/assets/images'",
1920
"build:minify-svg": "svgo -r -f ./",
2021
"build:playground": "webpack --mode=production --progress",
@@ -53,6 +54,10 @@
5354
],
5455
"*.json": "prettier --write",
5556
"*.md": "markdownlint --fix",
57+
"src/content/blog/*.md": [
58+
"node tools/update-blog-dates.js",
59+
"git add src/_data/blog-dates.json"
60+
],
5661
"**/*.svg": "npx svgo -r --multipass"
5762
},
5863
"gitHooks": {

0 commit comments

Comments
 (0)