Admin: add games from any list or itch.io collection (Check first, batches of 200, per-game ingest tracking from scripts/state/ingest_outcomes.json), followed collections and auto-approve run by the cron in one [auto] commit, bulk remove/edit up to 100 games in one commit, New games, Activity and Settings pages. D1 migration 0002 (applied to production before this merge). Policies (ToS, Privacy, Disclaimer, EN + VI) cover approval by the maintainer's rules; LEGAL_VERSION 2026-10-13. Web: the theme button shows the theme in use, no dark-mode flash (pre-paint script, hash in three CSPs), Charts tabs stay mounted (no rebuilt charts or replayed animations), 300 ms entrances, scrollbar gutter on mouse devices. Release 4.4.0 (changelog also covers #130). [skip-discuss] Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
/**
|
|
* itch.io game URLs out of any pasted or uploaded text: a plain list, CSV,
|
|
* Markdown, an HTML page or JSON (escaped "\/" slashes included). A link
|
|
* deeper into a game page (devlog, purchase…) counts as the game. The result
|
|
* is canonical (https://creator.itch.io/game, lower case), de-duplicated, in
|
|
* the order the games first appear.
|
|
*/
|
|
|
|
// The creator's subdomain, then the game's slug as the first path segment.
|
|
const GAME_URL = /(?:^|[^a-z0-9.-])(?:https?:\/\/)?([a-z0-9][a-z0-9-]*)\.itch\.io\/([a-z0-9][a-z0-9_-]*)/gi
|
|
// itch.io's own subdomains, never a creator.
|
|
const NOT_CREATORS = new Set(['www', 'static', 'api'])
|
|
|
|
export interface Extracted {
|
|
urls: string[]
|
|
/** Further mentions of a game already listed. */
|
|
duplicates: number
|
|
}
|
|
|
|
export function extractGameUrls(text: string): Extracted {
|
|
const seen = new Set<string>()
|
|
let duplicates = 0
|
|
for (const m of text.replace(/\\\//g, '/').matchAll(GAME_URL)) {
|
|
const creator = m[1].toLowerCase()
|
|
if (NOT_CREATORS.has(creator)) continue
|
|
const url = `https://${creator}.itch.io/${m[2].toLowerCase()}`
|
|
if (seen.has(url)) duplicates += 1
|
|
else seen.add(url)
|
|
}
|
|
return { urls: [...seen], duplicates }
|
|
}
|