hex/site/scripts/meetings.ts
Kit Langton 3209b5f962
site: add /hex/meetings showcase with a spoiler-free card and homepage links (#2912)
Serves the standalone Meetings showcase from public/meetings/ at
/hex/meetings/ (the Worker 301s /hex/meetings there so relative paths
resolve). `bun run import:meetings <bundle>` copies only the files the page
loads and drops session ids and the bundle's social tags; the build writes
the canonical address, Open Graph and Twitter tags for its origin and
refuses missing references or files over 25 MiB. Adds og-meetings.png
(Hex mark, "Hex Meetings", a meeting pill), Meetings links in the landing
page header and footer, and sitemap and llms.txt entries.
2026-11-26 15:41:40 -08:00

32 lines
1.7 KiB
TypeScript

// Finishes the Meetings showcase in the built site (public/meetings/ copied by
// Vite): writes its canonical address and social tags for this mode's origin
// into index.html, and refuses a file Workers static assets can't serve.
//
// bun scripts/meetings.ts --mode dev
import { getWorkerAssetsDir } from "@cloudflare/build-output-utils"
import { readFileSync, statSync, writeFileSync } from "node:fs"
import { join, resolve } from "node:path"
import { parseArgs } from "node:util"
import { originForMode } from "../src/base"
import { MEETINGS_CARD, MEETINGS_DIR, meetingsHead, runtimeFiles, stripHead } from "./meetings-bundle"
const { values } = parseArgs({ options: { mode: { type: "string" } } })
const origin = originForMode(values.mode)
const dir = join(getWorkerAssetsDir(resolve(import.meta.dirname, "..")), MEETINGS_DIR)
const bundle = runtimeFiles(dir)
if (bundle.missing.length) throw new Error(`Meetings names files it doesn't have: ${bundle.missing.map((m) => `${m.from} → ${m.ref}`).join(", ")}`)
// Workers static assets serve files up to 25 MiB.
const LIMIT = 25 * 1024 * 1024
let bytes = 0
for (const file of [...bundle.files, MEETINGS_CARD]) {
const size = statSync(join(dir, file)).size
if (size > LIMIT) throw new Error(`meetings/${file} is ${size} bytes, over the 25 MiB asset limit`)
bytes += size
}
const index = join(dir, "index.html")
const html = stripHead(readFileSync(index, "utf8"))
if (!html.includes("</head>")) throw new Error("meetings/index.html has no </head>")
writeFileSync(index, html.replace("</head>", `${meetingsHead(origin)}</head>`))
console.log(`Meetings: ${bundle.files.length + 1} files, ${(bytes / 1024 / 1024).toFixed(2)} MiB.`)