diff --git a/.github/workflows/deploy-docs-cf.yml b/.github/workflows/deploy-docs-cf.yml new file mode 100644 index 0000000..05ce2be --- /dev/null +++ b/.github/workflows/deploy-docs-cf.yml @@ -0,0 +1,52 @@ +name: Deploy docs to Cloudflare Pages + +on: + push: + branches: [main, master] + pull_request: + types: [opened, synchronize, reopened] + workflow_dispatch: + +concurrency: + group: deploy-docs-cf-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0 + with: + enable-cache: true + + - name: Install dependencies + run: uv sync + + - name: Override site_url for the Cloudflare build + run: | + sed -i 's|^site_url = .*|site_url = "https://owid-docs.pages.dev/"|' zensical.toml + + - name: Build docs + run: uv run zensical build --clean + + - name: Add _worker.js (path router for subprojects) + run: cp _worker.js site/_worker.js + + - name: Deploy to Cloudflare Pages + uses: cloudflare/wrangler-action@v3 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + command: >- + pages deploy site + --project-name=owid-docs + --branch=${{ github.head_ref || github.ref_name }} diff --git a/_worker.js b/_worker.js new file mode 100644 index 0000000..f74b9be --- /dev/null +++ b/_worker.js @@ -0,0 +1,32 @@ +// Cloudflare Pages Functions worker for the owid-docs project. +// +// When present at the deployment root, this file intercepts ALL requests +// for this Pages project. We use it as a thin router so that one custom +// domain (docs-cf.owid.io and later docs.owid.io) can transparently serve +// docs from multiple source repos: +// +// /projects/etl/* → proxied to https://owid-etl-docs.pages.dev/projects/etl/* +// everything else → served from this project's own static assets +// +// Each subproject keeps its own GitHub repo, its own CI, and its own +// Pages project (per-PR previews on *.pages.dev still work as today). +// Add a new route here whenever another subproject migrates to CF Pages. + +const SUBPROJECTS = { + "/projects/etl/": "https://owid-etl-docs.pages.dev", +}; + +export default { + async fetch(request, env) { + const url = new URL(request.url); + + for (const [prefix, origin] of Object.entries(SUBPROJECTS)) { + if (url.pathname.startsWith(prefix)) { + const target = `${origin}${url.pathname}${url.search}`; + return fetch(target, request); + } + } + + return env.ASSETS.fetch(request); + }, +};