Generate Sitemap #126
This file contains hidden or 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: Generate Sitemap | |
| on: | |
| push: | |
| branches: [ main ] | |
| paths: | |
| - 'src/pages/posts/**' | |
| - 'public/**' | |
| schedule: | |
| # Run daily at 4:13 AM UTC | |
| - cron: '13 4 * * *' | |
| workflow_dispatch: | |
| jobs: | |
| generate-sitemap: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build Astro site | |
| run: npm run build | |
| - name: Generate sitemap | |
| run: | | |
| npm install -D sitemap | |
| node scripts/generate-sitemap.js | |
| - name: Commit and push sitemap | |
| run: | | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| git add public/sitemap.xml | |
| git diff --staged --quiet || git commit -m "Update sitemap.xml" | |
| git push | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |