Skip to content

Commit

Permalink
Pre-commit hook for last_modified_date
Browse files Browse the repository at this point in the history
  • Loading branch information
djvill committed Aug 22, 2023
1 parent cb000eb commit c0dafda
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,28 @@ As a result, the repo doesn't have all the files to preview the page locally (i.
I decided this limitation was worth not clogging up the repository with a ton of Jekyll code.


### Page `last_modified_date`

Markdown files that have the `last_modified_date` parameter set in their YAML headers will have "Page last modified: DATE" appear [in the footer](https://github.com/just-the-docs/just-the-docs/blob/main/_includes/components/footer.html#L15-L19).
(To suppress this, just remove/don't add `last_modified_date` to the header.)
To have this parameter automatically updated when changes are committed to a page, add a pre-commit hook as the file `.git/hooks/pre-commit`:

```bash
#!/bin/sh
# Replace `last_modified_date` timestamp with current time
# Credit: https://mademistakes.com/notes/adding-last-modified-timestamps-with-git/

git diff --cached --name-status | egrep -i "^(A|M).*\.(md)$" | while read a b; do
cat $b | sed -b "/---.*/,/---.*/s/^last_modified_date:.*$/last_modified_date: $(date -u "+%Y-%m-%dT%H:%M:%S")/" > tmp
mv tmp $b
git add $b
done
```

Solution courtesy of https://mademistakes.com/notes/adding-last-modified-timestamps-with-git/.



## Repo contents

- `_includes/`: Content stubs (see [Jekyll doc](https://jekyllrb.com/docs/includes/))
Expand All @@ -48,6 +70,8 @@ I decided this limitation was worth not clogging up the repository with a ton of
- `./` (this folder):
- `.gitignore`: For [Git version control](https://git-scm.com/docs/gitignore)
- `_config.yml`: Site configuration file (see [Jekyll doc](https://jekyllrb.com/docs/configuration/))
- `_todo.md`: Site maintenance to-do list
- `404.md`: Custom "Page not found" error page (see [Jekyll doc](https://jekyllrb.com/tutorials/custom-404-page/))
- `LICENSE.md`: Markdown conversion of [legal code for CC BY-NC-SA 4.0 license](https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode)
- `README.md`: What you're reading right now!
- `SPLASH.md`: APLS homepage (aka splash page), injected via `<iframe>` into [apls.pitt.edu](https://apls.pitt.edu)
2 changes: 2 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ aux_links_new_tab: true
##Footer
##Config: https://just-the-docs.github.io/just-the-docs/docs/configuration/#footer-content
back_to_top: false
last_edit_timestamp: true
last_edit_time_format: "%B %-d, %Y"
gh_edit_link: true # show or hide edit this page link
gh_edit_link_text: "Edit this page on GitHub."
gh_edit_repository: "https://github.com/djvill/APLS" # the github URL for your repo
Expand Down
2 changes: 1 addition & 1 deletion _todo.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# TODO

- Set `#main-content > main` min-height so the footer never appears in the middle of the page (e.g., 404 page: https://djvill.github.io/APLS/files/blah%20blah)
- Something to do with [finding height of <hr> + <footer>](https://stackoverflow.com/a/23749355) and maybe also .main-header and doing some math
- 404 issue link: Prefill some values (https://github.com/isaacs/github/issues/99#issuecomment-24584307)
- Add glossary
- Mark words as `<span class="glossary">`, have them link to anchors on a glossary page
- Add "last edited" to custom_footer
- Convert Rmd to md

## Fun but not necessary
Expand Down
2 changes: 1 addition & 1 deletion files/custom-dictionary/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Custom dictionary
layout: default
permalink: /files/custom-dictionary
last_modified_at: 2023-08-22T20:14:44
last_modified_date: 2023-08-22T20:30:57
---

# {{ page.title }}
Expand Down

0 comments on commit c0dafda

Please sign in to comment.