Skip to content

Commit 63f2e2a

Browse files
authored
Generate timestamps on pre-commit (#58)
* Update last_modified_date on pre-commit * Update README * Add contributing and license section to README
1 parent 2830a8d commit 63f2e2a

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
#!/usr/bin/bash
1+
#!/usr/bin/env bash
2+
23
# Replace `last_modified_date` timestamp with current time
3-
# This script is used to update the `last_modified_date` timestamp in the frontmatter of all Markdown files in the current directory and subdirectories.
4+
# This script is used to update the `last_modified_date` timestamp
5+
# in the frontmatter of staged Markdown files.
6+
7+
# Get the list of staged Markdown files
8+
staged_files=$(git diff --cached --name-only --diff-filter=ACM | grep '\.md$')
49

5-
# Loop through all Markdown files in the current directory and subdirectories
6-
find . -type f -name "*.md" | while read file; do
7-
# Check if the file contains a frontmatter block
8-
if grep -q "^---" "$file"; then
10+
# Loop through each staged Markdown file
11+
echo "$staged_files" | while read file; do
12+
# Check if the file exists and contains a frontmatter block
13+
if [[ -f "$file" ]] && grep -q "^---" "$file"; then
14+
echo "Updating last_modified_date in $file"
915
# Get the last modified timestamp of the file
1016
last_modified_timestamp=$(stat -c %Y "$file")
1117

@@ -19,5 +25,8 @@ find . -type f -name "*.md" | while read file; do
1925
# If last_modified_date does not exist, add it after the first frontmatter delimiter
2026
sed -i "/^---/a last_modified_date: $last_modified_datetime_utc" "$file"
2127
fi
28+
29+
# Stage the updated file
30+
git add "$file"
2231
fi
2332
done

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
<a href="https://docs.gatewayd.io/">Documentation</a>
1313
</p>
1414

15+
> [!IMPORTANT]
16+
> The pre-commit hook is used to update the `last_modified_date` field in the frontmatter for each page. It will run automatically upon committing changes if you run the following commands to enable them:
17+
>
18+
> ```bash
19+
> ln .git/hooks/pre-commit .githooks/pre-commit/01-update-last-modified-date
20+
> git config core.hooksPath .githooks
21+
> ```
22+
1523
## Running the docs locally
1624
1725
The docs are built using [Jekyll](https://jekyllrb.com/) and the [just-the-docs](https://just-the-docs.github.io/just-the-docs/) theme. To run the docs locally, you need to have Git and Ruby installed. Then, install Jekyll and `bundler`:
@@ -54,10 +62,10 @@ For private repositories, you can set the `GITHUB_TOKEN` environment variable wi
5462

5563
The tag can be used multiple times in the same page. A single request will be made to the GitHub API to retrieve the latest tag name for each repository.
5664

57-
## Latest modified date
65+
## Contributing
5866

59-
The `generate_last_modified_data.sh` script is used to generate the `last_modified_date` data in the frontmatter for each page. It should be run manually before pushing the changes to the `main` branch.
67+
We welcome contributions from everyone. Just open an [issue](https://github.com/gatewayd-io/docs/issues) or send us a [pull request](https://github.com/gatewayd-io/docs/pulls).
6068

61-
```bash
62-
./generate_last_modified_data.sh
63-
```
69+
## License
70+
71+
GatewayD is licensed under the [Affero General Public License v3.0](https://github.com/gatewayd-io/docs/blob/main/LICENSE).

0 commit comments

Comments
 (0)