Skip to content

Commit

Permalink
Document restoring mtime for file.modified variable
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilafian committed Aug 17, 2024
1 parent 74ab9e9 commit e7d8cc2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ For example, CDN links for the packages `"@fortawesome/fontawesome-free"` and `"

### 7. Last Updated
The special `file` varaible can be leveraged to create a "Last Updated" field that is
automatically populated with the date the HTML was most recenlty modified.
automatically populated with the date the source file was most recently modified.

For example, an HTML file with following lines:
```html
Expand All @@ -207,7 +207,6 @@ For example, an HTML file with following lines:
<time datetime={{file.timestamp}}>{{file.modified}}</time>
</header>
```

will be transformed into something similar to:
```html
<header>
Expand All @@ -216,6 +215,20 @@ will be transformed into something similar to:
<time datetime=2030-04-07T07:01:36.037Z>April 7, 2030</time>
</header>
```
**Note:**
Be aware that `git checkout` deliberately resets file modification dates (`mtime`).&nbsp;
If you use GitHub Actions to publish your website, you'll need to restore file modification dates with a script or tool.
One tool that does this is [chetan/git-restore-mtime-action](https://github.com/marketplace/actions/git-restore-mtime):
```yaml
steps:
- uses: actions/checkout@v4
with:
ref: main #fetch the full git history of the "main"
fetch-depth: 0 #branch for git-restore-mtime-action
- uses: chetan/git-restore-mtime-action@v2
- uses: actions/setup-node@v4
```
For a working example, see: [publish-website.yaml](https://github.com/center-key/think-metric/blob/main/.github/workflows/publish-website.yaml)
## C) Application Code
Even though **replacer-util** is primarily intended for build scripts, the package can be used programmatically in ESM and TypeScript projects.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@eslint/js": "~9.9",
"@fortawesome/fontawesome-free": "~6.6",
"@types/fancy-log": "~2.0",
"@types/node": "~22.2",
"@types/node": "~22.3",
"add-dist-header": "~1.4",
"assert-deep-strict-equal": "~1.2",
"copy-file-util": "~1.2",
Expand Down

0 comments on commit e7d8cc2

Please sign in to comment.