website: the Discord member count next to the star count
The nav has advertised the repo's stars since the GitLab move but said nothing about the community, which is by now the larger number of the two. Both links now carry their count: GitLab ★ 185, Discord 1,084. Discord hands an invite's guild counts to anyone who appends ?with_counts=1 — no bot token, no server widget to switch on, and the API reflects the caller's Origin, so the browser may read it. The count is fetched exactly like the repo counts: once per tab, cached in sessionStorage, and failing soft — a blocked or revoked request leaves the link reading "Discord", the way it read before. The numbers panel on the home page gains a sixth cell for it and loses the "repo" in its caption, since the counts are no longer all from the repo. Six cells divide evenly where five left a hole, so the row that used to span the full width at the narrow breakpoint goes away: six, then three, then two.
This commit is contained in:
1 parent
523cfc9df7
commit
75fb168a03
7 files changed
+60
-30
No files matched your search
@@ -5,6 +5,12 @@
|
||||
|
||||
const GL_PROJECT = 'https://gitlab.com/api/v4/projects/DuarteSantos8%2Fopengym'
|
||||
|
||||
// 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
|
||||
// Origin, so the browser is allowed to read it. The code is the permanent invite in the
|
||||
// nav; if that invite is ever revoked this returns 404 and the count simply stays blank.
|
||||
const DC_INVITE = 'https://discord.com/api/v10/invites/e62jY6fwVb?with_counts=1'
|
||||
|
||||
/* ------------------------------------------------------- one panel controller
|
||||
The navigation sheet and the contents drawer are the same object with different
|
||||
contents: one opener, one close button, Escape, a tap outside, focus held inside
|
||||
@@ -256,6 +262,31 @@ function panel({ opener, panelEl, flag, closeBtn }) {
|
||||
} catch (e) { /* offline / rate-limited — leave placeholders */ }
|
||||
})()
|
||||
|
||||
/* --------------------------------------------------- Discord members (nav + specs)
|
||||
Same shape as the repo counts above, and just as optional: the placeholder next to
|
||||
the Discord link is empty, so a blocked or rate-limited request leaves the link
|
||||
reading exactly as it did before anyone counted anything. */
|
||||
;(async () => {
|
||||
const set = (id, v) => document.querySelectorAll('[data-dc="' + id + '"]').forEach(el => { el.textContent = v })
|
||||
try {
|
||||
let n = null
|
||||
const cached = sessionStorage.getItem('discord_members')
|
||||
if (cached) n = JSON.parse(cached)
|
||||
else {
|
||||
const r = await fetch(DC_INVITE)
|
||||
if (!r.ok) return
|
||||
const j = await r.json()
|
||||
n = j.approximate_member_count
|
||||
if (typeof n !== 'number') return
|
||||
sessionStorage.setItem('discord_members', JSON.stringify(n))
|
||||
}
|
||||
// Grouped like the other four-figure numbers on the page (1,324 exercises).
|
||||
const fmt = n.toLocaleString('en-US')
|
||||
set('members', fmt)
|
||||
set('members-n', fmt)
|
||||
} catch (e) { /* offline / blocked — the link keeps its plain label */ }
|
||||
})()
|
||||
|
||||
/* -------------------------------------------------------------- about timeline
|
||||
Built from the published GitLab releases, so the page updates itself with every
|
||||
release. The static entries marked data-fallback stay in place when the API is
|
||||
|
||||
Reference in new issue
Block a user