Skip to content

feat: add last updated date to blog posts #692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
7 changes: 7 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ module.exports = eleventyConfig => {
value1.concat(value2),
);

eleventyConfig.addFilter("lastUpdated", filepath => {
const relativePath = path.relative("src/content/blog", filepath);
const blogDates = require("./src/_data/blog-dates.json");

return new Date(blogDates[relativePath]);
});

/**
* ***************************************************************************************
* Plugins
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"lint:fix:scss": "stylelint \"**/*.scss\" --fix",
"fmt": "prettier --write .",
"fmt:check": "prettier --check .",
"start": "npm-run-all build:sass --parallel *:*:watch"
"start": "npm-run-all build:sass --parallel *:*:watch",
"init-blog-dates": "node tools/update-blog-dates.js --init"
},
"lint-staged": {
"**/*.{js,jsx}": [
Expand All @@ -53,6 +54,10 @@
],
"*.json": "prettier --write",
"*.md": "markdownlint --fix",
"src/content/blog/*.md": [
"node tools/update-blog-dates.js",
"git add src/_data/blog-dates.json"
],
"**/*.svg": "npx svgo -r --multipass"
},
"gitHooks": {
Expand Down
Loading