Add puzzle hints and per-word descriptions with sources

Hint is revealed on demand below the board while playing. After the game
ends, each word's description and source link are listed below the
puzzle, and hovering a solved word highlights its entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aidan Dona 2026-10-13 16:44:07 -05:00
parent 4a2309b589
commit b2f8e879ab
7 changed files with 141 additions and 21 deletions

View file

@ -23,10 +23,12 @@ db.exec(`CREATE TABLE IF NOT EXISTS games (
created_at TEXT NOT NULL DEFAULT (datetime('now')),
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
)`);
// Added after launch; existing databases get the column on first start.
if (!db.prepare('PRAGMA table_info(games)').all().some((c) => c.name === 'hint')) db.exec('ALTER TABLE games ADD COLUMN hint TEXT');
// Server's local date decides "today"; set TZ on the VPS to the timezone you want.
const today = () => new Date().toLocaleDateString('en-CA');
const toGame = (row) => row && { id: row.id, title: row.title, date: row.date, groups: JSON.parse(row.groups_json) };
const toGame = (row) => row && { id: row.id, title: row.title, date: row.date, hint: row.hint || '', groups: JSON.parse(row.groups_json) };
// A game is public once its date has arrived (undated games are always public).
const getPublic = (id) =>
@ -58,7 +60,7 @@ app.get('/puzzles', page('puzzles.html'));
app.get('/admin', page('admin.html'));
// ---- Player API (never sends group membership until solved or revealed) ----
const publicView = (g) => ({ id: g.id, title: g.title, date: g.date, words: shuffle(g.groups.flatMap((x) => x.words)) });
const publicView = (g) => ({ id: g.id, title: g.title, date: g.date, hint: g.hint, words: shuffle(g.groups.flatMap((x) => x.words)) });
app.get('/api/games', (req, res) => {
const rows = db
@ -116,10 +118,10 @@ function save(req, res, id) {
const { errors, game } = validateGame(req.body);
if (errors) return res.status(400).json({ errors });
try {
const args = [game.title, game.date, JSON.stringify(game.groups)];
const args = [game.title, game.date, game.hint || null, JSON.stringify(game.groups)];
const r = id
? db.prepare("UPDATE games SET title = ?, date = ?, groups_json = ?, updated_at = datetime('now') WHERE id = ?").run(...args, id)
: db.prepare('INSERT INTO games (title, date, groups_json) VALUES (?, ?, ?)').run(...args);
? db.prepare("UPDATE games SET title = ?, date = ?, hint = ?, groups_json = ?, updated_at = datetime('now') WHERE id = ?").run(...args, id)
: db.prepare('INSERT INTO games (title, date, hint, groups_json) VALUES (?, ?, ?, ?)').run(...args);
if (id && r.changes === 0) return res.status(404).json({ errors: ['Puzzle not found.'] });
res.json({ id: id || Number(r.lastInsertRowid) });
} catch (e) {