Count Visitors #32
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Count Visitors | |
on: | |
page_build | |
permissions: | |
contents: write | |
jobs: | |
count: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Update count | |
run: | | |
mkdir -p _data | |
DATE=$(TZ=UTC date +%Y-%m-%d) | |
# Create initial file if it doesn't exist | |
if [ ! -f "_data/visitors.json" ]; then | |
echo '{"total":0,"daily":{"'$DATE'":0}}' > _data/visitors.json | |
fi | |
# Update counts | |
jq --arg date "$DATE" \ | |
'.total += 1 | .daily[$date] = (.daily[$date] // 0) + 1' \ | |
_data/visitors.json > tmp.json && mv tmp.json _data/visitors.json | |
- name: Commit | |
run: | | |
git config user.name github-actions | |
git config user.email github-actions@github.com | |
git add _data/visitors.json | |
git commit -m "Update count" || exit 0 | |
git push |