|
4 | 4 | // title, image or template gives it a new URL and link previews refresh. Cards are English at |
5 | 5 | // every locale. |
6 | 6 | // |
7 | | -// OG Studio (a local design tool) can replace any card. It writes finished files and a manifest to |
8 | | -// src/asset/og-studio/: for each page an English PNG, an optional MP4 for og:video and an optional |
9 | | -// PNG for each locale. Pages in that manifest use its files; every other page renders here. |
| 7 | +// OG Studio (a local design tool) can replace any card. For each page it makes an English PNG, an |
| 8 | +// optional MP4 for og:video and an optional PNG for each locale, and writes a manifest to |
| 9 | +// src/asset/og-studio/manifest.json. Pages in that manifest use its files; every other page renders |
| 10 | +// here. A version 2 manifest has a `base` (/files/site/og): OG Studio uploads the files to the |
| 11 | +// files bucket there (MEDIA.md) and only the manifest is in git, so pages link `${base}/<file>` |
| 12 | +// and nothing is copied. A manifest without `base` (version 1) keeps its files beside it, and they |
| 13 | +// are copied into public/og/. |
10 | 14 | // |
11 | 15 | // This file is the cards' source of truth. The layout is David's template frame in Paper (the |
12 | 16 | // "OG images" file, frame "/ — dark"): a grid of #2e2e2e lines at x 72, 900 and 1128 and y 72, |
@@ -202,19 +206,25 @@ const fonts = [ |
202 | 206 | await mkdir(out, { recursive: true }) |
203 | 207 | const manifest: Record<string, OgEntry> = {} |
204 | 208 | const studio = await readStudio() |
| 209 | +const studioBase = studio?.base?.replace(/\/+$/, "") ?? "/og" |
205 | 210 | for (const [page, entry] of Object.entries(studio?.cards ?? {})) { |
206 | | - const files = [entry.image, entry.video, ...Object.values(entry.locales ?? {}).map((l) => l.image)].filter( |
207 | | - (file): file is string => Boolean(file), |
208 | | - ) |
209 | | - await Promise.all(files.map((file) => Bun.write(path.join(out, file), Bun.file(path.join(root, STUDIO, file))))) |
| 211 | + if (!studio?.base) { |
| 212 | + const files = [entry.image, entry.video, ...Object.values(entry.locales ?? {}).map((l) => l.image)].filter( |
| 213 | + (file): file is string => Boolean(file), |
| 214 | + ) |
| 215 | + await Promise.all(files.map((file) => Bun.write(path.join(out, file), Bun.file(path.join(root, STUDIO, file))))) |
| 216 | + } |
210 | 217 | manifest[page] = { |
211 | | - src: `/og/${entry.image}`, |
| 218 | + src: `${studioBase}/${entry.image}`, |
212 | 219 | alt: entry.alt, |
213 | | - ...(entry.video ? { video: `/og/${entry.video}` } : {}), |
| 220 | + ...(entry.video ? { video: `${studioBase}/${entry.video}` } : {}), |
214 | 221 | ...(entry.locales |
215 | 222 | ? { |
216 | 223 | locales: Object.fromEntries( |
217 | | - Object.entries(entry.locales).map(([locale, l]) => [locale, { src: `/og/${l.image}`, alt: l.alt }]), |
| 224 | + Object.entries(entry.locales).map(([locale, l]) => [ |
| 225 | + locale, |
| 226 | + { src: `${studioBase}/${l.image}`, alt: l.alt }, |
| 227 | + ]), |
218 | 228 | ), |
219 | 229 | } |
220 | 230 | : {}), |
@@ -244,11 +254,15 @@ await Promise.all( |
244 | 254 | (await readdir(out)).filter((file) => !keep.has(file)).map((file) => rm(path.join(out, file), { force: true })), |
245 | 255 | ) |
246 | 256 | await Bun.write(path.join(root, "src/lib/og-images.json"), JSON.stringify(manifest, null, 2) + "\n") |
247 | | -console.log(`og: ${Object.keys(manifest).length} cards in public/og (${Object.keys(studio?.cards ?? {}).length} from OG Studio)`) |
| 257 | +console.log( |
| 258 | + `og: ${Object.keys(manifest).length} cards (${Object.keys(studio?.cards ?? {}).length} from OG Studio${studio?.base ? ` at ${studioBase}` : ""})`, |
| 259 | +) |
248 | 260 |
|
249 | 261 | type OgEntry = { src: string; alt: string; video?: string; locales?: Record<string, { src: string; alt: string }> } |
250 | 262 |
|
251 | 263 | type Studio = { |
| 264 | + /** Version 2: where the files are served (the files bucket's /files/site/og). */ |
| 265 | + base?: string |
252 | 266 | cards: Record<string, { image: string; alt: string; video?: string; locales?: Record<string, { image: string; alt: string }> }> |
253 | 267 | } |
254 | 268 |
|
|
0 commit comments