How to automatically generate a last_updated entry in docs
https://gitlab.com/gitlab-com/gitlab-docs/merge_requests/87 introduced a last updated entry at the end of the docs. In order for the last update to show in a document, you need to add the following in the yaml frontmatter:
last_updated: 2017-09-09
Creating a raketask that updates the value automatically based on latest git commit would be great! For ref: https://stackoverflow.com/questions/36948807/edit-yaml-frontmatter-in-markdown-file.
From a bit of a search:
Method 1
Find last updated time:
git log -1 --format=%cd --date=format:'%d %B %Y' $file
which results to a format:
27 April 2017
Method 2
Different method, if we want to use the iso format in yaml frontmatter and output in human readable format:
git log -1 --date=short --format=%cd $file
and then parse with Ruby:
require "time"
ut = DateTime.parse("2017-04-27")
ut.strftime("%-d %B %Y")
When the update should happen
Would the update happen at release time (i.e. as part of the release managers tasks)?
Make this a requirement for each doc while we update them.
Here's what I think:
- At first, include it in all docs at once (the how is what I'm trying to figure out)
- Then, each time someone changes an md file, a test will be run to check whether the
last_updated
value was changed, if not the CI will fail. - To make this less of a burden to devs, a raketask will be provided that will perform this automatically. This has to be done smart though: check which files have changed compared to master, filter out markdown, check if
last_updated
exists or matches today's date, if not create/update it.