Site: GitHub is home again, GitLab a mirror

Nav, footer, the Elsewhere pads and every deep link point at github.com; GitLab keeps a pad
and a footer link as the mirror whose CI signs the APK. Stars, forks, issues and the About
timeline come from api.github.com again (new cache keys so a warm GitLab-era entry is not
misread). The dead-pad rules from the suspension weeks are gone. Cache-bust 17.
This commit is contained in:
Duarte Santos committed 2026-09-11 11:58:39 +02:00
1 parent 265bbc83f5
commit 0c18a808ce
7 files changed
+95 -93

No files matched your search

+20 -29
View File
@@ -1,9 +1,9 @@
// Behaviour for the openGym site: the header's navigation sheet, the contents
// drawer and its scrollspy, the scroll reveals, the demo frame, and the two things
// that come from the GitLab API (repo counts, release timeline).
// that come from the GitHub API (repo counts, release timeline).
// Every one of them fails soft — the page is complete without any of this running.
const GL_PROJECT = 'https://gitlab.com/api/v4/projects/DuarteSantos8%2Fopengym'
const GH_REPO = 'https://api.github.com/repos/DuarteSantos8/openGym'
// Discord publishes an invite's guild counts to anyone who asks for the invite with
// ?with_counts=1 — no bot token, no widget to enable, and the API reflects the caller's
@@ -226,33 +226,26 @@ function panel({ opener, panelEl, flag, closeBtn }) {
})()
/* ------------------------------------------------------- repo counts (nav + specs)
Points at gitlab.com while the GitHub account is suspended; switch the two API URLs
back to api.github.com once it is restored.
Back on api.github.com since 2026-09-11 — GitHub is the home of the project again and
GitLab only mirrors it. Unauthenticated, 60 requests an hour per IP, which the
sessionStorage cache keeps us well under.
The cache keys carry a _gl suffix: a visitor with a still-warm sessionStorage entry
from the gitea era would otherwise be read with the old field names and show NaN. */
The cache keys carry a _gh2 suffix: a visitor with a still-warm entry from the GitLab
weeks would otherwise be read with the old field names and show NaN. */
;(async () => {
const set = (id, v) => document.querySelectorAll('[data-gh="' + id + '"]').forEach(el => { el.textContent = v })
try {
let d = null
const cached = sessionStorage.getItem('repo_meta_gl')
const cached = sessionStorage.getItem('repo_meta_gh2')
if (cached) d = JSON.parse(cached)
else {
const r = await fetch(GL_PROJECT)
const r = await fetch(GH_REPO)
if (!r.ok) return
const j = await r.json()
// An unauthenticated project response carries star_count and forks_count and nothing
// else countable — open_issues_count is only there for a logged-in caller, so reading
// it here printed "undefined" on the live site. The issues endpoint answers it in the
// X-Total header instead, and GitLab lists that header in Access-Control-Expose-Headers,
// so the browser is allowed to read it. per_page=1 keeps the body to a single issue.
let issues = ''
try {
const ri = await fetch(GL_PROJECT + '/issues?state=opened&per_page=1')
if (ri.ok) issues = ri.headers.get('X-Total') || ''
} catch (e) { /* count stays blank rather than wrong */ }
d = { stars_count: j.star_count, forks_count: j.forks_count, open_issues_count: issues }
sessionStorage.setItem('repo_meta_gl', JSON.stringify(d))
// open_issues_count counts open pull requests too — GitHub's own repo header does the
// same, so the number matches what a visitor sees over there.
d = { stars_count: j.stargazers_count, forks_count: j.forks_count, open_issues_count: j.open_issues_count }
sessionStorage.setItem('repo_meta_gh2', JSON.stringify(d))
}
set('stars', '★ ' + d.stars_count)
set('stars-n', d.stars_count)
@@ -288,26 +281,24 @@ function panel({ opener, panelEl, flag, closeBtn }) {
})()
/* -------------------------------------------------------------- about timeline
Built from the published GitLab releases, so the page updates itself with every
Built from the published GitHub releases, so the page updates itself with every
release. The static entries marked data-fallback stay in place when the API is
unreachable; the hand-written first entry is always kept.
GitLab's release objects differ from Gitea's: the notes are `description` (not `body`),
the date is `released_at` (not `published_at`), the web link sits in `_links.self`, and
there is no draft/prerelease pair — a not-yet-released one is `upcoming_release`. */
Drafts and pre-releases are skipped; the notes are `body`, the date `published_at`. */
;(async () => {
const tl = document.getElementById('milestones')
if (!tl) return
try {
let rel = null
const cached = sessionStorage.getItem('repo_releases_gl')
const cached = sessionStorage.getItem('repo_releases_gh2')
if (cached) rel = JSON.parse(cached)
else {
const r = await fetch(GL_PROJECT + '/releases?per_page=100')
const r = await fetch(GH_REPO + '/releases?per_page=100')
if (!r.ok) return
rel = (await r.json()).filter(x => !x.upcoming_release)
.map(x => ({ tag: x.tag_name, name: x.name, at: x.released_at, body: x.description || '', url: (x._links && x._links.self) || ('https://gitlab.com/DuarteSantos8/opengym/-/releases/' + x.tag_name) }))
sessionStorage.setItem('repo_releases_gl', JSON.stringify(rel))
rel = (await r.json()).filter(x => !x.draft && !x.prerelease)
.map(x => ({ tag: x.tag_name, name: x.name || x.tag_name, at: x.published_at, body: x.body || '', url: x.html_url }))
sessionStorage.setItem('repo_releases_gh2', JSON.stringify(rel))
}
if (!rel.length) return
const fmt = d => new Date(d).toLocaleDateString('en-GB', { year: 'numeric', month: 'long', day: 'numeric' })