If you are using Git to track changes to your book (or other project), you can mark a major update with an annotated tag at the appropriate commit. The following code will automatically include that information in your book, showing the most recent changes first. If there are no tags, it will add nothing at all to your project.
``` {r echo=FALSE, results='asis'}
cmd0 = "git fetch --all --tags"
cmd1 = "git tag -l --sort=-*creatordate --format='%(*creatordate:short) | %(tag) | %(contents)'"
system(cmd0,intern=FALSE)
updates = system(cmd1,intern=TRUE)
if (length(updates) != 0) {
cat('#### Latest updates to this book {-}', updates, sep='\n\n')
}
```
The output will look like this:
Latest updates to this book
2020-09-22 | v0.1.2 | proofed through chapter 2 section 1
2020-08-16 | v0.1.1 | proofed through intro
2020-08-10 | v0.1 | full clean text, including footnotes
I'm pumped that I got it working, so I thought I'd share it here. Here are the commands necessary to make an annotated tag, if you don't know how:
How to create an annotated tag and push it to Github
- Creating a tag for the current commit:
- git tag -a v0.2 -m "full clean text, including footnotes"
- Creating a tag for an older commit:
- git tag -a v0.1 132e843 -m "full clean text, including footnotes"
- Push all your tags to Github:
To remove a tag, delete it locally and remotely, respectively, with these two commands (in case you make a mistake)
- git tag -d v0.1
- git push --delete origin v0.1
You could also show every commit, with its message, or just the 5 most recent ones, or any other info you can lookup with a git command by replacing cmd1 above with whatever gets you the info you want.
Hope you like it!
Edit: If you are only building locally and not using something like Travis CI, you don't need to push your tags to Github. You can just create them locally.