Merge pull request #6 from safeai-aus/codex/update-canonical-url-in-e… #92
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: Deploy MkDocs to GitHub Pages | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
concurrency: | |
group: pages | |
cancel-in-progress: true | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.11' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Build site | |
run: mkdocs build --strict --site-dir site | |
- name: Generate sitemap.xml | |
run: | | |
python - << 'PY' | |
import os, re | |
import xml.etree.ElementTree as ET | |
# Extract site_url without parsing YAML (handles Material emoji tags) | |
site_url = '' | |
with open('mkdocs.yml', 'r', encoding='utf-8') as f: | |
for line in f: | |
m = re.match(r"\s*site_url:\s*(\S+)", line) | |
if m: | |
site_url = m.group(1) | |
break | |
base_url = (site_url or '').rstrip('/') + '/' | |
site_dir = 'site' | |
urlset = ET.Element('urlset', xmlns='http://www.sitemaps.org/schemas/sitemap/0.9') | |
for root, _, files in os.walk(site_dir): | |
for name in files: | |
if not name.endswith('.html'): | |
continue | |
rel_path = os.path.relpath(os.path.join(root, name), site_dir) | |
if rel_path == '404.html': | |
continue | |
loc = base_url | |
if rel_path == 'index.html': | |
pass | |
else: | |
rel_url = rel_path.replace(os.sep, '/') | |
if rel_url.endswith('/index.html'): | |
rel_url = rel_url[:-10] | |
loc += rel_url | |
url = ET.SubElement(urlset, 'url') | |
ET.SubElement(url, 'loc').text = loc | |
ET.ElementTree(urlset).write(os.path.join(site_dir, 'sitemap.xml'), encoding='utf-8', xml_declaration=True) | |
PY | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: site | |
deploy: | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
needs: build | |
runs-on: ubuntu-latest | |
permissions: | |
pages: write | |
id-token: write | |
steps: | |
- name: Configure GitHub Pages | |
uses: actions/configure-pages@v5 | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 |