-
-
Notifications
You must be signed in to change notification settings - Fork 504
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
Use last commit as a date
front matter option
#142
Comments
This repository is now using lodash style issue management for enhancements. This means enhancement issues will now be closed instead of leaving them open. The enhancement backlog can be found here: https://github.com/11ty/eleventy/issues?utf8=%E2%9C%93&q=label%3Aneeds-votes+sort%3Areactions-%2B1-desc+ |
Related:
https://github.com/11ty/eleventy/blob/master/src/Template.js#L615 Maybe worth creating a new abstraction for template dates? |
I just wanted to point out that the discussion is mostly about the last commit date so far. There are considerations around first commit date as well, such as if this should operate as if the follow option was specified or not. This would have implications if a file was renamed. The correct behaviour is non-obvious as it would likely need to be dealt with on a case-by-case basis. Should there be a new config section to specify some of these options? or should it be specified in the front matter of each page? |
We currently have Would it be helpful to include I expect it might break the existing understanding of Or will we still need some git log wizardry to get a file's true Last modified (committed) date? |
I've been playing with some ideas and so far the most promising is by using git-date-extractor in a prebuild script that drops the created and modified dates into a global datafile. The problem is that the build times do take quite a long time, even after filtering to only files in the sitemap. 24 files takes about 40-ish seconds to crawl and generate in the repo. May have to look into caching results and truncating the search to recent commits. |
Thanks, @BrentARitchie. git ls-tree -r --name-only HEAD | while read filename; do echo "$(git log -n1 --format=%aI $filename) $filename"; done In case you can't read bash:
This yields a list of file names git knows about.
I'd suggest to replace the |
This adds a Importantly, if a file is not checked into See https://github.com/11ty/eleventy/blob/8f35e553f80a9a75da3b2eb1a923ecce87f65573/src/Util/DateGitLastUpdated.js and thanks to VuePress for the implementation! This is a little bit expensive so maybe use sparingly (or only in production?). Will pair nicely with ENV variables and directory data files: e.g. if(process.env.CONTEXT === "production") {
module.exports = {
date: "git Last Modified"
};
}
module.exports = {}; This is slated to ship with 1.0.1 |
On a project, I would need a "git First Commited", do you think it would possible to add it with a similar command? Here's how I currently get it in a Bash script: fileDate=$(git log --all --diff-filter=A --pretty=%x0a%ci --name-only | awk '
/^$/ { dateline=!dateline; next }
dateline { date=$0; next }
!seen[$0]++ { print date,$0 }
' | grep "$fileBasename" | head -1) Found it in https://stackoverflow.com/a/32894198/717195 |
@nhoizey can you file this as a separate issue? I’d be open to adding an config point for folks to add their own callbacks too |
Done: #2224 |
Has anyone tried this with Vercel? |
Good callout @kkga, probably worth adding a warning to the docs! |
This will alleviate the problem of deploying on a remote server and losing all of your file creation/updated dates and also make it unnecessary to hard code dates.
Inspired by vuepress https://vuepress.vuejs.org/default-theme-config/#last-updated
The text was updated successfully, but these errors were encountered: