diff --git a/.github/workflows/api.yml b/.github/workflows/api.yml index 906999c..3ce5a35 100644 --- a/.github/workflows/api.yml +++ b/.github/workflows/api.yml @@ -64,6 +64,10 @@ jobs: timeout-minutes: 15 # Repository settings can require a reviewer for this environment environment: production + permissions: + contents: read + # Only to start the Pages deploy below (workflow_dispatch) + actions: write env: WRANGLER_SEND_METRICS: "false" steps: @@ -102,3 +106,13 @@ jobs: env: CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} run: npx wrangler deploy + + # When one push changes the site and the API, both workflows start at + # once and the mirror can read the old Worker (that is how listing.json + # was missing after the sorting release). Rebuilding the mirror once the + # new Worker is live makes the order right; an unchanged catalog costs + # one request and reuses every file. + - name: Rebuild the Pages mirror from the new Worker + env: + GH_TOKEN: ${{ github.token }} + run: gh workflow run deploy-pages.yml --repo "$GITHUB_REPOSITORY" --ref main diff --git a/scripts/mirror_api.py b/scripts/mirror_api.py index ce8ad55..070e980 100644 --- a/scripts/mirror_api.py +++ b/scripts/mirror_api.py @@ -33,7 +33,7 @@ import os import sys from concurrent.futures import ThreadPoolExecutor -from urllib.parse import quote +from urllib.parse import quote, unquote import requests @@ -53,6 +53,23 @@ def write(out, path, data): f.write(data) +def write_file(out, path, data): + """A static file, plus a copy under its percent-decoded name. + + Some names hold a literal escape, e.g. `bmp280%2Bbme280_lilka.lua`. Keira + and the website request the name as written, and GitHub Pages decodes the + path first, so it looks for `bmp280+bme280_lilka.lua`. The decoded copy is + what that request finds; the literal one stays for encoded requests. + """ + write(out, path, data) + folder, name = path.rsplit("/", 1) + decoded = unquote(name) + # Only the file name is decoded, and never into another path: `%2F..` + # must not write outside the item's folder + if decoded != name and "/" not in decoded and "\\" not in decoded and decoded not in (".", ".."): + write(out, f"{folder}/{decoded}", data) + + def github_output(**values): target = os.environ.get("GITHUB_OUTPUT") if target: @@ -118,12 +135,12 @@ def fetch(job): # Unchanged version: identical bytes are already on Pages r = session.get(path_url(args.pages, path), timeout=120) if r.ok: - write(args.out, path, r.content) + write_file(args.out, path, r.content) counts["pages"] += 1 return r = session.get(path_url(api, path), headers=api_headers, timeout=120) r.raise_for_status() - write(args.out, path, r.content) + write_file(args.out, path, r.content) counts["api"] += 1 errors = [] diff --git a/site/script.js b/site/script.js index e90435d..d227f11 100644 --- a/site/script.js +++ b/site/script.js @@ -624,6 +624,9 @@ class LilkaRepository { try { const listing = await this.loadListing(this.currentType); + // Without listing.json only the fixed pages exist, sorted by id: a + // selector that cannot change anything would only look broken + document.querySelector('.list-toolbar').hidden = !listing; if (listing) { const sorted = this.sortItems(listing); this.totalPages = Math.max(1, Math.ceil(sorted.length / PAGE_SIZE)); diff --git a/site/styles.css b/site/styles.css index b894140..a3e8abb 100644 --- a/site/styles.css +++ b/site/styles.css @@ -1879,3 +1879,7 @@ footer { .rating-star:disabled { cursor: wait; } + +.list-toolbar[hidden] { + display: none; +}