Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/deploy-docs-cf.yml
Original file line number Diff line number Diff line change
@@ -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 }}
32 changes: 32 additions & 0 deletions _worker.js
Original file line number Diff line number Diff line change
@@ -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);
},
};
Loading