hashquiz 1.0.0-beta.6 → 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 +16 -0
- package/bin/hashquiz.js +323 -26
- 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,6 +60,21 @@ 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
|
|
|
64
80
|
### Theme
|
package/bin/hashquiz.js
CHANGED
|
@@ -5373,8 +5373,8 @@ function serveStatic(root, port, home, decksDir, publicDir) {
|
|
|
5373
5373
|
}
|
|
5374
5374
|
|
|
5375
5375
|
// packages/server/src/build.ts
|
|
5376
|
-
import { cpSync, existsSync as existsSync4, mkdirSync as
|
|
5377
|
-
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";
|
|
5378
5378
|
|
|
5379
5379
|
// packages/server/src/seo.ts
|
|
5380
5380
|
var TRUE = new Set(["1", "true", "yes"]);
|
|
@@ -5422,14 +5422,308 @@ function renderRobots(settings, hasSitemap) {
|
|
|
5422
5422
|
`);
|
|
5423
5423
|
}
|
|
5424
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
|
+
|
|
5425
5719
|
// packages/server/src/build.ts
|
|
5426
5720
|
function buildSite({ decksDir, outDir, publicDir, env = process.env }) {
|
|
5427
5721
|
const seo = seoFromEnv(env);
|
|
5428
|
-
const publicAbs = publicDir !== undefined ?
|
|
5722
|
+
const publicAbs = publicDir !== undefined ? resolve6(publicDir) : resolve6("public");
|
|
5429
5723
|
if (publicDir !== undefined && !(existsSync4(publicAbs) && statSync3(publicAbs).isDirectory())) {
|
|
5430
5724
|
throw new Error(`Public folder not found: ${publicDir}`);
|
|
5431
5725
|
}
|
|
5432
|
-
const decksAbs =
|
|
5726
|
+
const decksAbs = resolve6(decksDir);
|
|
5433
5727
|
if (!existsSync4(decksAbs))
|
|
5434
5728
|
throw new Error(`Decks folder not found: ${decksDir}`);
|
|
5435
5729
|
const decks = collectDecks(decksAbs);
|
|
@@ -5454,35 +5748,36 @@ function buildSite({ decksDir, outDir, publicDir, env = process.env }) {
|
|
|
5454
5748
|
const web = findWebDist();
|
|
5455
5749
|
if (!web)
|
|
5456
5750
|
throw new Error("Prebuilt web apps not found (in the hashquiz repo, run `bun run build:web` first)");
|
|
5457
|
-
const out =
|
|
5751
|
+
const out = resolve6(outDir);
|
|
5458
5752
|
if (out === decksAbs)
|
|
5459
5753
|
throw new Error("--out must differ from the decks folder");
|
|
5460
5754
|
rmSync(out, { recursive: true, force: true });
|
|
5461
|
-
|
|
5755
|
+
mkdirSync3(out, { recursive: true });
|
|
5462
5756
|
cpSync(web, out, { recursive: true });
|
|
5463
5757
|
const hasPublic = existsSync4(publicAbs) && statSync3(publicAbs).isDirectory();
|
|
5464
|
-
const
|
|
5465
|
-
|
|
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));
|
|
5466
5761
|
if (hasPublic)
|
|
5467
5762
|
cpSync(publicAbs, out, { recursive: true });
|
|
5468
|
-
const playerHtml =
|
|
5469
|
-
const themed = hasPublic && existsSync4(
|
|
5763
|
+
const playerHtml = resolve6(out, "index.html");
|
|
5764
|
+
const themed = hasPublic && existsSync4(resolve6(publicAbs, THEME_FILE));
|
|
5470
5765
|
const page = (html) => themed ? linkTheme(html) : html;
|
|
5471
|
-
|
|
5472
|
-
const hostHtml =
|
|
5766
|
+
writeFileSync2(playerHtml, page(applySeo(readFileSync3(playerHtml, "utf-8"), seo)));
|
|
5767
|
+
const hostHtml = resolve6(out, "host/index.html");
|
|
5473
5768
|
if (themed)
|
|
5474
|
-
|
|
5769
|
+
writeFileSync2(hostHtml, page(readFileSync3(hostHtml, "utf-8")));
|
|
5475
5770
|
const manifest = JSON.stringify(decks);
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
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)));
|
|
5479
5774
|
return decks.length;
|
|
5480
5775
|
}
|
|
5481
5776
|
|
|
5482
5777
|
// packages/backend-supabase/src/cli/edge-bundle.ts
|
|
5483
5778
|
import { existsSync as existsSync5 } from "fs";
|
|
5484
5779
|
import { mkdir } from "fs/promises";
|
|
5485
|
-
import { dirname as
|
|
5780
|
+
import { dirname as dirname4, join as join3 } from "path";
|
|
5486
5781
|
var EDGE_CORE_FILE = "functions/_shared/solo-core.js";
|
|
5487
5782
|
var EDGE_CORE_BANNER = `import { Buffer } from "node:buffer";
|
|
5488
5783
|
`;
|
|
@@ -5500,7 +5795,7 @@ async function bundleEdgeCore(outFile) {
|
|
|
5500
5795
|
${result.logs.map((l) => String(l)).join(`
|
|
5501
5796
|
`)}`);
|
|
5502
5797
|
}
|
|
5503
|
-
await mkdir(
|
|
5798
|
+
await mkdir(dirname4(outFile), { recursive: true });
|
|
5504
5799
|
await Bun.write(outFile, EDGE_CORE_BANNER + stripModulePathComments(await result.outputs[0].text()));
|
|
5505
5800
|
}
|
|
5506
5801
|
function stripModulePathComments(code) {
|
|
@@ -5511,7 +5806,7 @@ if (false) {}
|
|
|
5511
5806
|
import { existsSync as existsSync6, statSync as statSync4 } from "fs";
|
|
5512
5807
|
import { cp, mkdtemp, rm } from "fs/promises";
|
|
5513
5808
|
import { tmpdir } from "os";
|
|
5514
|
-
import { basename, join as join4, resolve as
|
|
5809
|
+
import { basename, join as join4, resolve as resolve7 } from "path";
|
|
5515
5810
|
var USAGE = "Usage: hashquiz supabase deploy --project <ref> [--site-url <url>] [--dry-run]";
|
|
5516
5811
|
var SECRET_ENV = ["SUPABASE_ACCESS_TOKEN", "SUPABASE_DB_PASSWORD"];
|
|
5517
5812
|
function supabaseDeploySteps(o) {
|
|
@@ -5531,13 +5826,13 @@ function isProject(dir) {
|
|
|
5531
5826
|
function findSupabaseDir() {
|
|
5532
5827
|
const here = import.meta.dirname;
|
|
5533
5828
|
const candidates = [
|
|
5534
|
-
|
|
5535
|
-
|
|
5829
|
+
resolve7(here, "../supabase"),
|
|
5830
|
+
resolve7(here, "../../supabase")
|
|
5536
5831
|
];
|
|
5537
5832
|
return candidates.find(isProject) ?? null;
|
|
5538
5833
|
}
|
|
5539
5834
|
async function copySupabaseProject(src, destSupabaseDir, edgeCore) {
|
|
5540
|
-
const coreFile =
|
|
5835
|
+
const coreFile = resolve7(src, EDGE_CORE_FILE);
|
|
5541
5836
|
if (edgeCore === "copy" && !existsSync6(coreFile)) {
|
|
5542
5837
|
throw new Error(`supabase: ${EDGE_CORE_FILE} missing in ${src} (run \`bun run build:edge\`)`);
|
|
5543
5838
|
}
|
|
@@ -5550,7 +5845,7 @@ async function copySupabaseProject(src, destSupabaseDir, edgeCore) {
|
|
|
5550
5845
|
filter: (p) => {
|
|
5551
5846
|
if (basename(p).startsWith(".env") && !statSync4(p).isDirectory())
|
|
5552
5847
|
return false;
|
|
5553
|
-
return edgeCore === "copy" ||
|
|
5848
|
+
return edgeCore === "copy" || resolve7(p) !== coreFile;
|
|
5554
5849
|
}
|
|
5555
5850
|
});
|
|
5556
5851
|
}
|
|
@@ -5655,7 +5950,7 @@ async function supabaseCommand(args, env, run = defaultRunner, log = console.log
|
|
|
5655
5950
|
}
|
|
5656
5951
|
// packages/server/src/cli.ts
|
|
5657
5952
|
import { readFileSync as readFileSync4 } from "fs";
|
|
5658
|
-
import { resolve as
|
|
5953
|
+
import { resolve as resolve8 } from "path";
|
|
5659
5954
|
var [, , command, arg, ...flags] = process.argv;
|
|
5660
5955
|
function printUsage() {
|
|
5661
5956
|
console.log(`
|
|
@@ -5674,7 +5969,9 @@ function printUsage() {
|
|
|
5674
5969
|
HASHQUIZ_SOLO_SCORING, HASHQUIZ_PLAYER_URL
|
|
5675
5970
|
(or their VITE_* names) from the environment, and
|
|
5676
5971
|
HASHQUIZ_SITE_URL, HASHQUIZ_LANG,
|
|
5677
|
-
HASHQUIZ_INDEXABLE for search engines
|
|
5972
|
+
HASHQUIZ_INDEXABLE for search engines, and
|
|
5973
|
+
HASHQUIZ_CATALOG=true for the public quiz
|
|
5974
|
+
pages under /quiz/.
|
|
5678
5975
|
supabase deploy --project <ref> [--site-url <url>] [--dry-run]
|
|
5679
5976
|
Deploy the solo backend to a Supabase project:
|
|
5680
5977
|
migrations, the solo-submit Edge Function and its
|
|
@@ -5737,7 +6034,7 @@ if (command === "dev") {
|
|
|
5737
6034
|
process.exit(1);
|
|
5738
6035
|
}
|
|
5739
6036
|
try {
|
|
5740
|
-
const content = readFileSync4(
|
|
6037
|
+
const content = readFileSync4(resolve8(arg), "utf-8");
|
|
5741
6038
|
const quiz = parseQuizFile(content);
|
|
5742
6039
|
const result = validateQuiz(quiz);
|
|
5743
6040
|
if (result.valid) {
|
package/package.json
CHANGED