Skip to content

docs: contents update at 2024-11-17 16:55:26 #6

docs: contents update at 2024-11-17 16:55:26

docs: contents update at 2024-11-17 16:55:26 #6

name: Update Last Modified Date
on:
push:
branches:
- blog
workflow_dispatch:
jobs:
updateLastModified:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'
- name: Install dependencies
run: bundle install
- name: Update last_modified_at field
run: |
posts_dir="_posts"
for post_path in $(find "$posts_dir" -name "*.md"); do
commit_count=$(git rev-list --count HEAD "$post_path")
last_modified=$(git log -1 --pretty="%ad" --date=format:'%Y-%m-%d %H:%M %z' "$post_path" | xargs)
content=$(cat "$post_path")
if [[ "$content" =~ ^date:\ (.+) ]]; then
if [[ "$content" =~ ^last_modified_at: ]]; then
sed -i "s/^last_modified_at:.*/last_modified_at: $last_modified/" "$post_path"
elif [[ $commit_count -gt 1 ]]; then
sed -i "/^date: /a last_modified_at: $last_modified" "$post_path"
fi
fi
done
- name: Commit changes
run: |
git config --global user.name "GitHub Action"
git config --global user.email "[email protected]"
git add _posts/*.md
git commit -m "Update last_modified_at field in posts" || echo "No changes to commit"
deployToCloudflare:
runs-on: ubuntu-latest
needs: updateLastModified # Ensure this runs after the updateLastModified job
steps:
- name: Push changes
run: git push origin blog
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}