hashquiz 1.0.0-beta.5 → 1.0.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/bin/hashquiz.js +357 -34
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -50,6 +50,7 @@ from the environment:
|
|
|
50
50
|
| `HASHQUIZ_SITE_URL` | Public URL of the site (e.g. `https://hashquiz.ai`): canonical, `og:url`, absolute `og:image`, sitemap line of `robots.txt` |
|
|
51
51
|
| `HASHQUIZ_LANG` | `<html lang>` of the player page, e.g. `fr` (default `en`) |
|
|
52
52
|
| `HASHQUIZ_INDEXABLE` | `true` lets search engines index the player page (default: `noindex`). The host is always `noindex` |
|
|
53
|
+
| `HASHQUIZ_CATALOG` | `true` writes the public quiz catalogue (below). Off by default: each deploy decides to list its decks |
|
|
53
54
|
|
|
54
55
|
### Search engines and link previews
|
|
55
56
|
|
|
@@ -59,8 +60,40 @@ The player page ships a description, Open Graph tags and a 1200×630 `og.png`, a
|
|
|
59
60
|
Files in `public/` (or the folder given with `--public`) are copied to the site root last, so a decks repository
|
|
60
61
|
can add `llms.txt` or `sitemap.xml`, or replace `og.png` and `robots.txt`. The `Sitemap:` line of the generated
|
|
61
62
|
`robots.txt` appears only when `public/` holds a `sitemap.xml` and `HASHQUIZ_SITE_URL` is set.
|
|
63
|
+
With `HASHQUIZ_CATALOG=true`, `build` also writes a public catalogue in plain HTML, readable by search engines and
|
|
64
|
+
AI assistants without JavaScript:
|
|
65
|
+
|
|
66
|
+
| Path | Content |
|
|
67
|
+
| --- | --- |
|
|
68
|
+
| `/quiz/` | Every deck: title, description, tags, difficulty, number of questions |
|
|
69
|
+
| `/quiz/<slug>/` | One deck: description, author, tags, difficulty, links to host it and play it solo (`solo: true`) |
|
|
70
|
+
| `/quiz/tag/<tag>/` | The decks carrying a tag |
|
|
71
|
+
| `/404.html` | Not-found page linking to the catalogue |
|
|
72
|
+
| `/sitemap.xml` | Every catalogue page, when `HASHQUIZ_SITE_URL` is set (a `public/sitemap.xml` replaces it) |
|
|
73
|
+
|
|
74
|
+
No page shows a question or an answer. The pages carry JSON-LD (`ItemList`, `Quiz`, `BreadcrumbList`).
|
|
75
|
+
The slug comes from the deck folder (`decks/docker-basics/index.hashquiz.md` → `docker-basics`).
|
|
76
|
+
Labels are in French when `HASHQUIZ_LANG` starts with `fr`, in English otherwise.
|
|
77
|
+
|
|
62
78
|
Background: [SEO audit](https://github.com/WhiteWoodTech/hashquiz/blob/develop/docs/SEO_AUDIT.md).
|
|
63
79
|
|
|
80
|
+
### Theme
|
|
81
|
+
|
|
82
|
+
A `public/theme.css` restyles the site without forking the engine: `build` (and `dev` from the package) links it
|
|
83
|
+
last in the player and host pages, so a `:root` block there overrides the `--hq-*` tokens (colors, fonts, radii,
|
|
84
|
+
offset shadows, particles). Replace `favicon.svg` (and `favicon-32.png`, `apple-touch-icon.png`) the same way.
|
|
85
|
+
Token list: [design system](https://github.com/WhiteWoodTech/hashquiz/blob/develop/docs/DESIGN_SYSTEM.md#deck-repository-theme).
|
|
86
|
+
|
|
87
|
+
```css
|
|
88
|
+
/* public/theme.css */
|
|
89
|
+
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');
|
|
90
|
+
:root {
|
|
91
|
+
--hq-bg: #1a1e1f;
|
|
92
|
+
--hq-accent: #5c7063;
|
|
93
|
+
--hq-font-display: 'Roboto', system-ui, sans-serif;
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
64
97
|
The `VITE_*` names (`VITE_TRANSPORT`, …) are accepted too. The prebuilt apps carry no
|
|
65
98
|
settings of their own: whatever `hashquiz-config.js` says (including `local` and `browser`) is what they use.
|
|
66
99
|
|
package/bin/hashquiz.js
CHANGED
|
@@ -5273,6 +5273,16 @@ function repoDecksDir(repoRoot) {
|
|
|
5273
5273
|
return existsSync2(local) ? local : resolve3(repoRoot, "tests/fixtures");
|
|
5274
5274
|
}
|
|
5275
5275
|
|
|
5276
|
+
// packages/server/src/theme.ts
|
|
5277
|
+
var THEME_FILE = "theme.css";
|
|
5278
|
+
var THEME_LINK = `<link rel="stylesheet" href="/${THEME_FILE}">`;
|
|
5279
|
+
function linkTheme(html) {
|
|
5280
|
+
if (html.includes(THEME_LINK))
|
|
5281
|
+
return html;
|
|
5282
|
+
return html.replace("</head>", ` ${THEME_LINK}
|
|
5283
|
+
</head>`);
|
|
5284
|
+
}
|
|
5285
|
+
|
|
5276
5286
|
// packages/server/src/dev.ts
|
|
5277
5287
|
function resolveDevTarget(arg, opts) {
|
|
5278
5288
|
const target = resolve4(arg);
|
|
@@ -5307,8 +5317,12 @@ function devCommand(arg, port, decksFlag) {
|
|
|
5307
5317
|
console.error("Prebuilt web apps not found: reinstall the hashquiz package.");
|
|
5308
5318
|
process.exit(1);
|
|
5309
5319
|
}
|
|
5310
|
-
|
|
5311
|
-
|
|
5320
|
+
const publicDir = resolve4("public");
|
|
5321
|
+
const pub = existsSync3(publicDir) && statSync2(publicDir).isDirectory() ? publicDir : null;
|
|
5322
|
+
serveStatic(web, 3031, "/host/", decksDir, pub);
|
|
5323
|
+
serveStatic(web, 3032, "/", decksDir, pub);
|
|
5324
|
+
if (pub && existsSync3(join2(pub, THEME_FILE)))
|
|
5325
|
+
console.log(` Theme: ${join2(pub, THEME_FILE)}`);
|
|
5312
5326
|
console.log(` Host app: http://localhost:3031/host/
|
|
5313
5327
|
Player app: http://localhost:3032/
|
|
5314
5328
|
`);
|
|
@@ -5326,7 +5340,7 @@ function devCommand(arg, port, decksFlag) {
|
|
|
5326
5340
|
`);
|
|
5327
5341
|
});
|
|
5328
5342
|
}
|
|
5329
|
-
function serveStatic(root, port, home, decksDir) {
|
|
5343
|
+
function serveStatic(root, port, home, decksDir, publicDir) {
|
|
5330
5344
|
const config = renderConfigScript({ transport: "local", soloScoring: "browser" });
|
|
5331
5345
|
Bun.serve({
|
|
5332
5346
|
port,
|
|
@@ -5341,20 +5355,26 @@ function serveStatic(root, port, home, decksDir) {
|
|
|
5341
5355
|
}
|
|
5342
5356
|
if (pathname === "/" && home !== "/")
|
|
5343
5357
|
return Response.redirect(home, 302);
|
|
5344
|
-
const
|
|
5345
|
-
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5358
|
+
const themed = publicDir !== null && existsSync3(join2(publicDir, THEME_FILE));
|
|
5359
|
+
const page = async (path) => new Response(themed ? linkTheme(await Bun.file(path).text()) : Bun.file(path), { headers: { "Content-Type": "text/html; charset=utf-8" } });
|
|
5360
|
+
for (const base of publicDir ? [publicDir, root] : [root]) {
|
|
5361
|
+
const file = resolve4(join2(base, decodeURIComponent(pathname)));
|
|
5362
|
+
if (!file.startsWith(base))
|
|
5363
|
+
return new Response("Not found", { status: 404 });
|
|
5364
|
+
if (existsSync3(file) && statSync2(file).isFile())
|
|
5365
|
+
return file.endsWith(".html") ? page(file) : new Response(Bun.file(file));
|
|
5366
|
+
const dirIndex = join2(file, "index.html");
|
|
5367
|
+
if (base === root && existsSync3(dirIndex))
|
|
5368
|
+
return page(dirIndex);
|
|
5369
|
+
}
|
|
5370
|
+
return page(pathname.startsWith("/host") ? join2(root, "host/index.html") : join2(root, "index.html"));
|
|
5351
5371
|
}
|
|
5352
5372
|
});
|
|
5353
5373
|
}
|
|
5354
5374
|
|
|
5355
5375
|
// packages/server/src/build.ts
|
|
5356
|
-
import { cpSync, existsSync as existsSync4, mkdirSync as
|
|
5357
|
-
import { resolve as
|
|
5376
|
+
import { cpSync, existsSync as existsSync4, mkdirSync as mkdirSync3, readFileSync as readFileSync3, rmSync, statSync as statSync3, writeFileSync as writeFileSync2 } from "fs";
|
|
5377
|
+
import { resolve as resolve6 } from "path";
|
|
5358
5378
|
|
|
5359
5379
|
// packages/server/src/seo.ts
|
|
5360
5380
|
var TRUE = new Set(["1", "true", "yes"]);
|
|
@@ -5402,14 +5422,308 @@ function renderRobots(settings, hasSitemap) {
|
|
|
5402
5422
|
`);
|
|
5403
5423
|
}
|
|
5404
5424
|
|
|
5425
|
+
// packages/server/src/catalog.ts
|
|
5426
|
+
import { mkdirSync as mkdirSync2, writeFileSync } from "fs";
|
|
5427
|
+
import { dirname as dirname3, resolve as resolve5 } from "path";
|
|
5428
|
+
var TEXT = {
|
|
5429
|
+
fr: {
|
|
5430
|
+
catalogTitle: "Tous les quiz",
|
|
5431
|
+
catalogIntro: "Quiz multijoueurs en temps r\xE9el, \xE9crits en Markdown. Lancez-en un sur grand \xE9cran, les joueurs r\xE9pondent depuis leur t\xE9l\xE9phone.",
|
|
5432
|
+
home: "Accueil",
|
|
5433
|
+
quizzes: "Quiz",
|
|
5434
|
+
questions: (n) => `${n} question${n > 1 ? "s" : ""}`,
|
|
5435
|
+
perGame: (n) => `${n} par partie`,
|
|
5436
|
+
difficulty: { easy: "facile", medium: "moyen", hard: "difficile" },
|
|
5437
|
+
by: "par",
|
|
5438
|
+
solo: "Jouable en solo",
|
|
5439
|
+
host: "Animer ce quiz",
|
|
5440
|
+
playSolo: "Jouer en solo",
|
|
5441
|
+
tag: (t) => `Quiz sur ${t}`,
|
|
5442
|
+
notFound: "Page introuvable",
|
|
5443
|
+
notFoundText: "Cette page n'existe pas. Les quiz sont tous sur le catalogue.",
|
|
5444
|
+
seeCatalog: "Voir les quiz"
|
|
5445
|
+
},
|
|
5446
|
+
en: {
|
|
5447
|
+
catalogTitle: "All quizzes",
|
|
5448
|
+
catalogIntro: "Real-time multiplayer quizzes written in Markdown. Run one on a big screen, players answer from their phones.",
|
|
5449
|
+
home: "Home",
|
|
5450
|
+
quizzes: "Quizzes",
|
|
5451
|
+
questions: (n) => `${n} question${n > 1 ? "s" : ""}`,
|
|
5452
|
+
perGame: (n) => `${n} per game`,
|
|
5453
|
+
difficulty: { easy: "easy", medium: "medium", hard: "hard" },
|
|
5454
|
+
by: "by",
|
|
5455
|
+
solo: "Playable solo",
|
|
5456
|
+
host: "Host this quiz",
|
|
5457
|
+
playSolo: "Play solo",
|
|
5458
|
+
tag: (t) => `${t} quizzes`,
|
|
5459
|
+
notFound: "Page not found",
|
|
5460
|
+
notFoundText: "This page does not exist. Every quiz is in the catalogue.",
|
|
5461
|
+
seeCatalog: "Browse quizzes"
|
|
5462
|
+
}
|
|
5463
|
+
};
|
|
5464
|
+
function catalogEnabled(env) {
|
|
5465
|
+
return ["1", "true", "yes"].includes((env.HASHQUIZ_CATALOG ?? "").trim().toLowerCase());
|
|
5466
|
+
}
|
|
5467
|
+
var slugify = (s) => s.normalize("NFD").replace(/[\u0300-\u036F]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
5468
|
+
function deckSlug(id) {
|
|
5469
|
+
const path = id.replace(/(^|\/)index\.hashquiz\.md$/, "").replace(/\.hashquiz\.md$/, "");
|
|
5470
|
+
return path.split("/").map(slugify).filter(Boolean).join("/") || "quiz";
|
|
5471
|
+
}
|
|
5472
|
+
var tagSlug = (tag) => slugify(tag) || encodeURIComponent(tag.toLowerCase());
|
|
5473
|
+
function catalogDecks(entries) {
|
|
5474
|
+
const used = new Set;
|
|
5475
|
+
return entries.map(({ id, content }) => ({ id, quiz: parseQuizFile(content) })).sort((a, b) => (a.quiz.meta.title || a.id).localeCompare(b.quiz.meta.title || b.id)).map(({ id, quiz }) => {
|
|
5476
|
+
const base = deckSlug(id);
|
|
5477
|
+
let slug = base;
|
|
5478
|
+
for (let i = 2;used.has(slug) || slug === "tag"; i++)
|
|
5479
|
+
slug = `${base}-${i}`;
|
|
5480
|
+
used.add(slug);
|
|
5481
|
+
return { id, slug, quiz };
|
|
5482
|
+
});
|
|
5483
|
+
}
|
|
5484
|
+
var esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
5485
|
+
var ldJson = (data) => JSON.stringify(data).replace(/</g, "\\u003c");
|
|
5486
|
+
function difficultyOf(quiz) {
|
|
5487
|
+
if (quiz.meta.targetDifficulty)
|
|
5488
|
+
return quiz.meta.targetDifficulty;
|
|
5489
|
+
const score = { easy: 1, medium: 2, hard: 3 };
|
|
5490
|
+
const avg = quiz.questions.reduce((s, q) => s + score[q.difficulty], 0) / (quiz.questions.length || 1);
|
|
5491
|
+
return avg < 1.67 ? "easy" : avg < 2.34 ? "medium" : "hard";
|
|
5492
|
+
}
|
|
5493
|
+
var abs = (ctx, path) => ctx.siteUrl ? `${ctx.siteUrl}${path}` : path;
|
|
5494
|
+
var CSS = `
|
|
5495
|
+
:root{--bg:#130A42;--card:#1d1258;--text:#F9F8F8;--muted:#c9c3e6;--violet:#6523EE;--purple:#A833F5}
|
|
5496
|
+
*{box-sizing:border-box}
|
|
5497
|
+
body{margin:0;background:var(--bg);color:var(--text);font:16px/1.6 system-ui,-apple-system,"Segoe UI",sans-serif}
|
|
5498
|
+
a{color:#d3b4ff}
|
|
5499
|
+
header,main,footer{max-width:960px;margin:0 auto;padding:0 16px}
|
|
5500
|
+
header{display:flex;align-items:center;gap:12px;padding-top:20px;padding-bottom:8px}
|
|
5501
|
+
header img{width:40px;height:40px;border-radius:10px}
|
|
5502
|
+
header a{color:var(--text);text-decoration:none;font-weight:700}
|
|
5503
|
+
nav.crumbs{font-size:14px;color:var(--muted)}
|
|
5504
|
+
nav.crumbs a{color:var(--muted)}
|
|
5505
|
+
h1{font-size:clamp(28px,5vw,40px);line-height:1.2;margin:16px 0 8px}
|
|
5506
|
+
h2{margin-top:40px}
|
|
5507
|
+
.intro{color:var(--muted);font-size:18px}
|
|
5508
|
+
.grid{list-style:none;padding:0;display:grid;gap:16px;grid-template-columns:repeat(auto-fill,minmax(260px,1fr))}
|
|
5509
|
+
.card{background:var(--card);border-radius:14px;padding:18px}
|
|
5510
|
+
.card h2,.card h3{margin:0 0 6px;font-size:20px}
|
|
5511
|
+
.card p{margin:6px 0;color:var(--muted)}
|
|
5512
|
+
.meta{display:flex;flex-wrap:wrap;gap:8px;font-size:14px;color:var(--muted);padding:0;list-style:none}
|
|
5513
|
+
.tags{display:flex;flex-wrap:wrap;gap:6px;padding:0;list-style:none}
|
|
5514
|
+
.tags a{display:inline-block;font-size:13px;padding:2px 10px;border-radius:999px;background:#2a1b73;text-decoration:none;color:var(--text)}
|
|
5515
|
+
.actions{display:flex;flex-wrap:wrap;gap:12px;margin:20px 0}
|
|
5516
|
+
.btn{display:inline-block;padding:10px 18px;border-radius:10px;background:var(--violet);color:#fff;text-decoration:none;font-weight:600}
|
|
5517
|
+
.btn.alt{background:transparent;border:2px solid var(--purple)}
|
|
5518
|
+
footer{color:var(--muted);font-size:14px;padding-top:40px;padding-bottom:40px}
|
|
5519
|
+
`;
|
|
5520
|
+
function page(ctx, o) {
|
|
5521
|
+
const url = abs(ctx, o.path);
|
|
5522
|
+
const lds = o.ld.map((d) => `<script type="application/ld+json">${ldJson(d)}</script>`).join(`
|
|
5523
|
+
`);
|
|
5524
|
+
return `<!DOCTYPE html>
|
|
5525
|
+
<html lang="${esc(ctx.langTag)}">
|
|
5526
|
+
<head>
|
|
5527
|
+
<meta charset="UTF-8">
|
|
5528
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
5529
|
+
<title>${esc(o.title)}</title>
|
|
5530
|
+
<meta name="description" content="${esc(o.description)}">
|
|
5531
|
+
<meta name="theme-color" content="#130A42">
|
|
5532
|
+
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
|
|
5533
|
+
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
|
|
5534
|
+
${ctx.siteUrl ? `<link rel="canonical" href="${esc(url)}">
|
|
5535
|
+
<meta property="og:url" content="${esc(url)}">
|
|
5536
|
+
` : ""}<meta property="og:type" content="website">
|
|
5537
|
+
<meta property="og:site_name" content="HashQuiz">
|
|
5538
|
+
<meta property="og:title" content="${esc(o.title)}">
|
|
5539
|
+
<meta property="og:description" content="${esc(o.description)}">
|
|
5540
|
+
<meta property="og:image" content="${esc(abs(ctx, "/og.png"))}">
|
|
5541
|
+
<meta name="twitter:card" content="summary_large_image">
|
|
5542
|
+
<style>${CSS}</style>
|
|
5543
|
+
${lds}
|
|
5544
|
+
</head>
|
|
5545
|
+
<body>
|
|
5546
|
+
<header><a href="/quiz/"><img src="/favicon.svg" alt=""></a><a href="/quiz/">HashQuiz</a></header>
|
|
5547
|
+
<main>
|
|
5548
|
+
${o.body}
|
|
5549
|
+
</main>
|
|
5550
|
+
<footer>HashQuiz \xB7 <a href="https://github.com/WhiteWoodTech/hashquiz">GitHub</a></footer>
|
|
5551
|
+
</body>
|
|
5552
|
+
</html>
|
|
5553
|
+
`;
|
|
5554
|
+
}
|
|
5555
|
+
function crumbs(ctx, items) {
|
|
5556
|
+
const html = `<nav class="crumbs" aria-label="breadcrumb">${items.map((c, i) => i === items.length - 1 ? esc(c.name) : `<a href="${esc(c.path)}">${esc(c.name)}</a>`).join(" \u203A ")}</nav>`;
|
|
5557
|
+
const ld = {
|
|
5558
|
+
"@context": "https://schema.org",
|
|
5559
|
+
"@type": "BreadcrumbList",
|
|
5560
|
+
itemListElement: items.map((c, i) => ({ "@type": "ListItem", position: i + 1, name: c.name, item: abs(ctx, c.path) }))
|
|
5561
|
+
};
|
|
5562
|
+
return { html, ld };
|
|
5563
|
+
}
|
|
5564
|
+
function tagList(tags) {
|
|
5565
|
+
if (!tags.length)
|
|
5566
|
+
return "";
|
|
5567
|
+
return `<ul class="tags">${tags.map((t) => `<li><a href="/quiz/tag/${tagSlug(t)}/">#${esc(t)}</a></li>`).join("")}</ul>`;
|
|
5568
|
+
}
|
|
5569
|
+
function metaLine(ctx, quiz) {
|
|
5570
|
+
const t = TEXT[ctx.lang];
|
|
5571
|
+
const items = [t.questions(quiz.questions.length)];
|
|
5572
|
+
if (quiz.meta.maxQuestions && quiz.meta.maxQuestions < quiz.questions.length)
|
|
5573
|
+
items.push(t.perGame(quiz.meta.maxQuestions));
|
|
5574
|
+
items.push(t.difficulty[difficultyOf(quiz)]);
|
|
5575
|
+
if (quiz.meta.solo)
|
|
5576
|
+
items.push(t.solo);
|
|
5577
|
+
return `<ul class="meta">${items.map((i) => `<li>${esc(i)}</li>`).join('<li aria-hidden="true">\xB7</li>')}</ul>`;
|
|
5578
|
+
}
|
|
5579
|
+
function deckCard(ctx, d) {
|
|
5580
|
+
const { meta } = d.quiz;
|
|
5581
|
+
return `<li class="card"><h2><a href="/quiz/${d.slug}/">${esc(meta.title || d.id)}</a></h2>
|
|
5582
|
+
${meta.description ? `<p>${esc(meta.description.trim())}</p>` : ""}
|
|
5583
|
+
${metaLine(ctx, d.quiz)}
|
|
5584
|
+
${tagList(meta.tags)}</li>`;
|
|
5585
|
+
}
|
|
5586
|
+
function quizLd(ctx, d, path) {
|
|
5587
|
+
const { meta } = d.quiz;
|
|
5588
|
+
return {
|
|
5589
|
+
"@context": "https://schema.org",
|
|
5590
|
+
"@type": "Quiz",
|
|
5591
|
+
name: meta.title || d.id,
|
|
5592
|
+
...meta.description && { description: meta.description.trim() },
|
|
5593
|
+
url: abs(ctx, path),
|
|
5594
|
+
inLanguage: ctx.langTag,
|
|
5595
|
+
isAccessibleForFree: true,
|
|
5596
|
+
educationalLevel: difficultyOf(d.quiz),
|
|
5597
|
+
...meta.tags.length && { keywords: meta.tags.join(", ") },
|
|
5598
|
+
...meta.author && { author: { "@type": "Person", name: meta.author } }
|
|
5599
|
+
};
|
|
5600
|
+
}
|
|
5601
|
+
function renderCatalog(decks, seo) {
|
|
5602
|
+
const lang = seo.lang?.toLowerCase().startsWith("fr") ? "fr" : "en";
|
|
5603
|
+
const ctx = { lang, langTag: seo.lang ?? "en", ...seo.siteUrl && { siteUrl: seo.siteUrl } };
|
|
5604
|
+
const t = TEXT[lang];
|
|
5605
|
+
const files = [];
|
|
5606
|
+
const home = { name: t.quizzes, path: "/quiz/" };
|
|
5607
|
+
{
|
|
5608
|
+
const c = crumbs(ctx, [home]);
|
|
5609
|
+
files.push({
|
|
5610
|
+
path: "quiz/index.html",
|
|
5611
|
+
content: page(ctx, {
|
|
5612
|
+
path: "/quiz/",
|
|
5613
|
+
title: `${t.catalogTitle} \xB7 HashQuiz`,
|
|
5614
|
+
description: t.catalogIntro,
|
|
5615
|
+
body: `<h1>${esc(t.catalogTitle)}</h1>
|
|
5616
|
+
<p class="intro">${esc(t.catalogIntro)}</p>
|
|
5617
|
+
<ul class="grid">${decks.map((d) => deckCard(ctx, d)).join(`
|
|
5618
|
+
`)}</ul>`,
|
|
5619
|
+
ld: [
|
|
5620
|
+
{
|
|
5621
|
+
"@context": "https://schema.org",
|
|
5622
|
+
"@type": "ItemList",
|
|
5623
|
+
name: t.catalogTitle,
|
|
5624
|
+
itemListElement: decks.map((d, i) => ({ "@type": "ListItem", position: i + 1, url: abs(ctx, `/quiz/${d.slug}/`), name: d.quiz.meta.title || d.id }))
|
|
5625
|
+
},
|
|
5626
|
+
c.ld
|
|
5627
|
+
]
|
|
5628
|
+
})
|
|
5629
|
+
});
|
|
5630
|
+
}
|
|
5631
|
+
for (const d of decks) {
|
|
5632
|
+
const { meta, questions } = d.quiz;
|
|
5633
|
+
const title = meta.title || d.id;
|
|
5634
|
+
const description = (meta.description ?? "").trim() || `${title} \xB7 ${t.questions(questions.length)}`;
|
|
5635
|
+
const path = `/quiz/${d.slug}/`;
|
|
5636
|
+
const actions = `<div class="actions"><a class="btn" href="/host/">${esc(t.host)}</a>${meta.solo ? `<a class="btn alt" href="/#/solo/${encodeURIComponent(d.id)}">${esc(t.playSolo)}</a>` : ""}</div>`;
|
|
5637
|
+
const header = `<h1>${esc(title)}</h1>
|
|
5638
|
+
${meta.description ? `<p class="intro">${esc(meta.description.trim())}</p>
|
|
5639
|
+
` : ""}${metaLine(ctx, d.quiz)}
|
|
5640
|
+
${meta.author ? `<p>${esc(t.by)} ${esc(meta.author)}</p>
|
|
5641
|
+
` : ""}${tagList(meta.tags)}`;
|
|
5642
|
+
const c = crumbs(ctx, [home, { name: title, path }]);
|
|
5643
|
+
files.push({
|
|
5644
|
+
path: `quiz/${d.slug}/index.html`,
|
|
5645
|
+
content: page(ctx, {
|
|
5646
|
+
path,
|
|
5647
|
+
title: `${title} \xB7 HashQuiz`,
|
|
5648
|
+
description,
|
|
5649
|
+
body: `${c.html}
|
|
5650
|
+
${header}
|
|
5651
|
+
${actions}`,
|
|
5652
|
+
ld: [quizLd(ctx, d, path), c.ld]
|
|
5653
|
+
})
|
|
5654
|
+
});
|
|
5655
|
+
}
|
|
5656
|
+
const byTag = new Map;
|
|
5657
|
+
for (const d of decks) {
|
|
5658
|
+
for (const tag of new Set(d.quiz.meta.tags)) {
|
|
5659
|
+
const key = tagSlug(tag);
|
|
5660
|
+
const entry = byTag.get(key) ?? { label: tag, decks: [] };
|
|
5661
|
+
entry.decks.push(d);
|
|
5662
|
+
byTag.set(key, entry);
|
|
5663
|
+
}
|
|
5664
|
+
}
|
|
5665
|
+
for (const [key, { label, decks: tagged }] of byTag) {
|
|
5666
|
+
const path = `/quiz/tag/${key}/`;
|
|
5667
|
+
const c = crumbs(ctx, [home, { name: `#${label}`, path }]);
|
|
5668
|
+
files.push({
|
|
5669
|
+
path: `quiz/tag/${key}/index.html`,
|
|
5670
|
+
content: page(ctx, {
|
|
5671
|
+
path,
|
|
5672
|
+
title: `${t.tag(label)} \xB7 HashQuiz`,
|
|
5673
|
+
description: `${t.tag(label)} : ${tagged.map((d) => d.quiz.meta.title || d.id).join(", ")}`,
|
|
5674
|
+
body: `${c.html}
|
|
5675
|
+
<h1>${esc(t.tag(label))}</h1>
|
|
5676
|
+
<ul class="grid">${tagged.map((d) => deckCard(ctx, d)).join(`
|
|
5677
|
+
`)}</ul>`,
|
|
5678
|
+
ld: [c.ld]
|
|
5679
|
+
})
|
|
5680
|
+
});
|
|
5681
|
+
}
|
|
5682
|
+
files.push({
|
|
5683
|
+
path: "404.html",
|
|
5684
|
+
content: page(ctx, {
|
|
5685
|
+
path: "/404.html",
|
|
5686
|
+
title: `${t.notFound} \xB7 HashQuiz`,
|
|
5687
|
+
description: t.notFoundText,
|
|
5688
|
+
body: `<h1>${esc(t.notFound)}</h1>
|
|
5689
|
+
<p class="intro">${esc(t.notFoundText)}</p>
|
|
5690
|
+
<div class="actions"><a class="btn" href="/quiz/">${esc(t.seeCatalog)}</a></div>`,
|
|
5691
|
+
ld: []
|
|
5692
|
+
}).replace('<meta name="theme-color"', `<meta name="robots" content="noindex">
|
|
5693
|
+
<meta name="theme-color"`)
|
|
5694
|
+
});
|
|
5695
|
+
if (seo.siteUrl) {
|
|
5696
|
+
const urls = files.filter((f) => f.path.endsWith("index.html")).map((f) => `${seo.siteUrl}/${f.path.replace(/index\.html$/, "").split("/").map(encodeURIComponent).join("/")}`);
|
|
5697
|
+
files.push({
|
|
5698
|
+
path: "sitemap.xml",
|
|
5699
|
+
content: `<?xml version="1.0" encoding="UTF-8"?>
|
|
5700
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
5701
|
+
${urls.map((u) => ` <url><loc>${esc(u)}</loc></url>`).join(`
|
|
5702
|
+
`)}
|
|
5703
|
+
</urlset>
|
|
5704
|
+
`
|
|
5705
|
+
});
|
|
5706
|
+
}
|
|
5707
|
+
return files;
|
|
5708
|
+
}
|
|
5709
|
+
function writeCatalog(outDir, entries, seo) {
|
|
5710
|
+
const files = renderCatalog(catalogDecks(entries), seo);
|
|
5711
|
+
for (const f of files) {
|
|
5712
|
+
const target = resolve5(outDir, f.path);
|
|
5713
|
+
mkdirSync2(dirname3(target), { recursive: true });
|
|
5714
|
+
writeFileSync(target, f.content);
|
|
5715
|
+
}
|
|
5716
|
+
return files.map((f) => f.path);
|
|
5717
|
+
}
|
|
5718
|
+
|
|
5405
5719
|
// packages/server/src/build.ts
|
|
5406
5720
|
function buildSite({ decksDir, outDir, publicDir, env = process.env }) {
|
|
5407
5721
|
const seo = seoFromEnv(env);
|
|
5408
|
-
const publicAbs = publicDir !== undefined ?
|
|
5722
|
+
const publicAbs = publicDir !== undefined ? resolve6(publicDir) : resolve6("public");
|
|
5409
5723
|
if (publicDir !== undefined && !(existsSync4(publicAbs) && statSync3(publicAbs).isDirectory())) {
|
|
5410
5724
|
throw new Error(`Public folder not found: ${publicDir}`);
|
|
5411
5725
|
}
|
|
5412
|
-
const decksAbs =
|
|
5726
|
+
const decksAbs = resolve6(decksDir);
|
|
5413
5727
|
if (!existsSync4(decksAbs))
|
|
5414
5728
|
throw new Error(`Decks folder not found: ${decksDir}`);
|
|
5415
5729
|
const decks = collectDecks(decksAbs);
|
|
@@ -5434,30 +5748,36 @@ function buildSite({ decksDir, outDir, publicDir, env = process.env }) {
|
|
|
5434
5748
|
const web = findWebDist();
|
|
5435
5749
|
if (!web)
|
|
5436
5750
|
throw new Error("Prebuilt web apps not found (in the hashquiz repo, run `bun run build:web` first)");
|
|
5437
|
-
const out =
|
|
5751
|
+
const out = resolve6(outDir);
|
|
5438
5752
|
if (out === decksAbs)
|
|
5439
5753
|
throw new Error("--out must differ from the decks folder");
|
|
5440
5754
|
rmSync(out, { recursive: true, force: true });
|
|
5441
|
-
|
|
5755
|
+
mkdirSync3(out, { recursive: true });
|
|
5442
5756
|
cpSync(web, out, { recursive: true });
|
|
5443
5757
|
const hasPublic = existsSync4(publicAbs) && statSync3(publicAbs).isDirectory();
|
|
5444
|
-
const
|
|
5445
|
-
|
|
5758
|
+
const catalog = catalogEnabled(env) ? writeCatalog(out, decks, seo) : [];
|
|
5759
|
+
const hasSitemap = catalog.includes("sitemap.xml") || hasPublic && existsSync4(resolve6(publicAbs, "sitemap.xml"));
|
|
5760
|
+
writeFileSync2(resolve6(out, "robots.txt"), renderRobots(seo, hasSitemap));
|
|
5446
5761
|
if (hasPublic)
|
|
5447
5762
|
cpSync(publicAbs, out, { recursive: true });
|
|
5448
|
-
const playerHtml =
|
|
5449
|
-
|
|
5763
|
+
const playerHtml = resolve6(out, "index.html");
|
|
5764
|
+
const themed = hasPublic && existsSync4(resolve6(publicAbs, THEME_FILE));
|
|
5765
|
+
const page = (html) => themed ? linkTheme(html) : html;
|
|
5766
|
+
writeFileSync2(playerHtml, page(applySeo(readFileSync3(playerHtml, "utf-8"), seo)));
|
|
5767
|
+
const hostHtml = resolve6(out, "host/index.html");
|
|
5768
|
+
if (themed)
|
|
5769
|
+
writeFileSync2(hostHtml, page(readFileSync3(hostHtml, "utf-8")));
|
|
5450
5770
|
const manifest = JSON.stringify(decks);
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
|
|
5771
|
+
writeFileSync2(resolve6(out, "host/decks.json"), manifest);
|
|
5772
|
+
writeFileSync2(resolve6(out, "decks.json"), manifest);
|
|
5773
|
+
writeFileSync2(resolve6(out, "hashquiz-config.js"), renderConfigScript(configFromEnv(env)));
|
|
5454
5774
|
return decks.length;
|
|
5455
5775
|
}
|
|
5456
5776
|
|
|
5457
5777
|
// packages/backend-supabase/src/cli/edge-bundle.ts
|
|
5458
5778
|
import { existsSync as existsSync5 } from "fs";
|
|
5459
5779
|
import { mkdir } from "fs/promises";
|
|
5460
|
-
import { dirname as
|
|
5780
|
+
import { dirname as dirname4, join as join3 } from "path";
|
|
5461
5781
|
var EDGE_CORE_FILE = "functions/_shared/solo-core.js";
|
|
5462
5782
|
var EDGE_CORE_BANNER = `import { Buffer } from "node:buffer";
|
|
5463
5783
|
`;
|
|
@@ -5475,7 +5795,7 @@ async function bundleEdgeCore(outFile) {
|
|
|
5475
5795
|
${result.logs.map((l) => String(l)).join(`
|
|
5476
5796
|
`)}`);
|
|
5477
5797
|
}
|
|
5478
|
-
await mkdir(
|
|
5798
|
+
await mkdir(dirname4(outFile), { recursive: true });
|
|
5479
5799
|
await Bun.write(outFile, EDGE_CORE_BANNER + stripModulePathComments(await result.outputs[0].text()));
|
|
5480
5800
|
}
|
|
5481
5801
|
function stripModulePathComments(code) {
|
|
@@ -5486,7 +5806,7 @@ if (false) {}
|
|
|
5486
5806
|
import { existsSync as existsSync6, statSync as statSync4 } from "fs";
|
|
5487
5807
|
import { cp, mkdtemp, rm } from "fs/promises";
|
|
5488
5808
|
import { tmpdir } from "os";
|
|
5489
|
-
import { basename, join as join4, resolve as
|
|
5809
|
+
import { basename, join as join4, resolve as resolve7 } from "path";
|
|
5490
5810
|
var USAGE = "Usage: hashquiz supabase deploy --project <ref> [--site-url <url>] [--dry-run]";
|
|
5491
5811
|
var SECRET_ENV = ["SUPABASE_ACCESS_TOKEN", "SUPABASE_DB_PASSWORD"];
|
|
5492
5812
|
function supabaseDeploySteps(o) {
|
|
@@ -5506,13 +5826,13 @@ function isProject(dir) {
|
|
|
5506
5826
|
function findSupabaseDir() {
|
|
5507
5827
|
const here = import.meta.dirname;
|
|
5508
5828
|
const candidates = [
|
|
5509
|
-
|
|
5510
|
-
|
|
5829
|
+
resolve7(here, "../supabase"),
|
|
5830
|
+
resolve7(here, "../../supabase")
|
|
5511
5831
|
];
|
|
5512
5832
|
return candidates.find(isProject) ?? null;
|
|
5513
5833
|
}
|
|
5514
5834
|
async function copySupabaseProject(src, destSupabaseDir, edgeCore) {
|
|
5515
|
-
const coreFile =
|
|
5835
|
+
const coreFile = resolve7(src, EDGE_CORE_FILE);
|
|
5516
5836
|
if (edgeCore === "copy" && !existsSync6(coreFile)) {
|
|
5517
5837
|
throw new Error(`supabase: ${EDGE_CORE_FILE} missing in ${src} (run \`bun run build:edge\`)`);
|
|
5518
5838
|
}
|
|
@@ -5525,7 +5845,7 @@ async function copySupabaseProject(src, destSupabaseDir, edgeCore) {
|
|
|
5525
5845
|
filter: (p) => {
|
|
5526
5846
|
if (basename(p).startsWith(".env") && !statSync4(p).isDirectory())
|
|
5527
5847
|
return false;
|
|
5528
|
-
return edgeCore === "copy" ||
|
|
5848
|
+
return edgeCore === "copy" || resolve7(p) !== coreFile;
|
|
5529
5849
|
}
|
|
5530
5850
|
});
|
|
5531
5851
|
}
|
|
@@ -5630,7 +5950,7 @@ async function supabaseCommand(args, env, run = defaultRunner, log = console.log
|
|
|
5630
5950
|
}
|
|
5631
5951
|
// packages/server/src/cli.ts
|
|
5632
5952
|
import { readFileSync as readFileSync4 } from "fs";
|
|
5633
|
-
import { resolve as
|
|
5953
|
+
import { resolve as resolve8 } from "path";
|
|
5634
5954
|
var [, , command, arg, ...flags] = process.argv;
|
|
5635
5955
|
function printUsage() {
|
|
5636
5956
|
console.log(`
|
|
@@ -5649,7 +5969,9 @@ function printUsage() {
|
|
|
5649
5969
|
HASHQUIZ_SOLO_SCORING, HASHQUIZ_PLAYER_URL
|
|
5650
5970
|
(or their VITE_* names) from the environment, and
|
|
5651
5971
|
HASHQUIZ_SITE_URL, HASHQUIZ_LANG,
|
|
5652
|
-
HASHQUIZ_INDEXABLE for search engines
|
|
5972
|
+
HASHQUIZ_INDEXABLE for search engines, and
|
|
5973
|
+
HASHQUIZ_CATALOG=true for the public quiz
|
|
5974
|
+
pages under /quiz/.
|
|
5653
5975
|
supabase deploy --project <ref> [--site-url <url>] [--dry-run]
|
|
5654
5976
|
Deploy the solo backend to a Supabase project:
|
|
5655
5977
|
migrations, the solo-submit Edge Function and its
|
|
@@ -5666,7 +5988,8 @@ function printUsage() {
|
|
|
5666
5988
|
--out <dir> Output folder for build (default: dist)
|
|
5667
5989
|
--public <dir> Files copied to the site root by build, e.g.
|
|
5668
5990
|
robots.txt, llms.txt, og.png (default: ./public
|
|
5669
|
-
when it exists)
|
|
5991
|
+
when it exists). A theme.css there overrides the
|
|
5992
|
+
--hq-* design tokens (build and dev).
|
|
5670
5993
|
`);
|
|
5671
5994
|
}
|
|
5672
5995
|
if (!command || command === "--help" || command === "-h") {
|
|
@@ -5711,7 +6034,7 @@ if (command === "dev") {
|
|
|
5711
6034
|
process.exit(1);
|
|
5712
6035
|
}
|
|
5713
6036
|
try {
|
|
5714
|
-
const content = readFileSync4(
|
|
6037
|
+
const content = readFileSync4(resolve8(arg), "utf-8");
|
|
5715
6038
|
const quiz = parseQuizFile(content);
|
|
5716
6039
|
const result = validateQuiz(quiz);
|
|
5717
6040
|
if (result.valid) {
|
package/package.json
CHANGED