Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate timestamps on pre-commit #58

Merged
merged 3 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#!/usr/bin/bash
#!/usr/bin/env bash

# Replace `last_modified_date` timestamp with current time
# This script is used to update the `last_modified_date` timestamp in the frontmatter of all Markdown files in the current directory and subdirectories.
# This script is used to update the `last_modified_date` timestamp
# in the frontmatter of staged Markdown files.

# Get the list of staged Markdown files
staged_files=$(git diff --cached --name-only --diff-filter=ACM | grep '\.md$')

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

Expand All @@ -19,5 +25,8 @@ find . -type f -name "*.md" | while read file; do
# If last_modified_date does not exist, add it after the first frontmatter delimiter
sed -i "/^---/a last_modified_date: $last_modified_datetime_utc" "$file"
fi

# Stage the updated file
git add "$file"
fi
done
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
<a href="https://docs.gatewayd.io/">Documentation</a>
</p>

> [!IMPORTANT]
> 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:
>
> ```bash
> ln .git/hooks/pre-commit .githooks/pre-commit/01-update-last-modified-date
> git config core.hooksPath .githooks
> ```

## Running the docs locally

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`:
Expand Down Expand Up @@ -54,10 +62,10 @@ For private repositories, you can set the `GITHUB_TOKEN` environment variable wi

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.

## Latest modified date
## Contributing

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.
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).

```bash
./generate_last_modified_data.sh
```
## License

GatewayD is licensed under the [Affero General Public License v3.0](https://github.com/gatewayd-io/docs/blob/main/LICENSE).
Loading