diff --git a/.github/workflows/generate-sitemap.yml b/.github/workflows/generate-sitemap.yml new file mode 100644 index 0000000..b49f930 --- /dev/null +++ b/.github/workflows/generate-sitemap.yml @@ -0,0 +1,54 @@ +name: Generate and publish sitemap + +on: + schedule: + - cron: '42 0 * * *' + push: + branches: + - main + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +jobs: + generate-sitemap: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Setup Pages + id: pages + uses: actions/configure-pages@v5 + + - name: Generate sitemap + run: python generate.py + + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: ./dist + + deploy: + runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + needs: generate-sitemap + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d3e7da2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +dist/*.xml diff --git a/Procfile b/Procfile deleted file mode 100644 index 91d3ca2..0000000 --- a/Procfile +++ /dev/null @@ -1 +0,0 @@ -web: gunicorn -w 4 -b 0.0.0.0:5000 app:app diff --git a/app.py b/app.py deleted file mode 100644 index c35d5bb..0000000 --- a/app.py +++ /dev/null @@ -1,22 +0,0 @@ -from datetime import datetime, UTC - -from flask import Flask, make_response -from flask_caching import Cache - -from generate import generate - -app = Flask(__name__) - -app.config["CACHE_TYPE"] = "FileSystemCache" -app.config["CACHE_DIR"] = "/tmp" -cache = Cache(app) - - -@app.route("/sitemap.xml") -@cache.cached(timeout=3600 * 3) -def sitemap(): - response = make_response(generate(write=False)) - response.headers["Content-Type"] = "application/xml; charset=utf-8" - last_modified = datetime.now(UTC).strftime('%a, %d %b %Y %H:%M:%S GMT') - response.headers["Last-Modified"] = last_modified - return response diff --git a/dist/.gitkeep b/dist/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt index f5c23a7..f229360 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1 @@ requests -flask -gunicorn -flask-caching