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
14 changes: 14 additions & 0 deletions .github/workflows/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
23 changes: 20 additions & 3 deletions scripts/mirror_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down Expand Up @@ -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 = []
Expand Down
3 changes: 3 additions & 0 deletions site/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 4 additions & 0 deletions site/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -1879,3 +1879,7 @@ footer {
.rating-star:disabled {
cursor: wait;
}

.list-toolbar[hidden] {
display: none;
}
Loading