Skip to content

Commit 33aefad

Browse files
chore(site): serve OG Studio link cards from the files bucket, add docs previews (#63560)
Co-authored-by: Adam <2363879+adamdotdevin@users.noreply.github.com>
1 parent 1a85993 commit 33aefad

185 files changed

Lines changed: 129 additions & 51 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎services/site/MEDIA.md‎

Lines changed: 40 additions & 1 deletion

‎services/site/script/og.ts‎

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
// title, image or template gives it a new URL and link previews refresh. Cards are English at
55
// every locale.
66
//
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/.
1014
//
1115
// This file is the cards' source of truth. The layout is David's template frame in Paper (the
1216
// "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 = [
202206
await mkdir(out, { recursive: true })
203207
const manifest: Record<string, OgEntry> = {}
204208
const studio = await readStudio()
209+
const studioBase = studio?.base?.replace(/\/+$/, "") ?? "/og"
205210
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+
}
210217
manifest[page] = {
211-
src: `/og/${entry.image}`,
218+
src: `${studioBase}/${entry.image}`,
212219
alt: entry.alt,
213-
...(entry.video ? { video: `/og/${entry.video}` } : {}),
220+
...(entry.video ? { video: `${studioBase}/${entry.video}` } : {}),
214221
...(entry.locales
215222
? {
216223
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+
]),
218228
),
219229
}
220230
: {}),
@@ -244,11 +254,15 @@ await Promise.all(
244254
(await readdir(out)).filter((file) => !keep.has(file)).map((file) => rm(path.join(out, file), { force: true })),
245255
)
246256
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+
)
248260

249261
type OgEntry = { src: string; alt: string; video?: string; locales?: Record<string, { src: string; alt: string }> }
250262

251263
type Studio = {
264+
/** Version 2: where the files are served (the files bucket's /files/site/og). */
265+
base?: string
252266
cards: Record<string, { image: string; alt: string; video?: string; locales?: Record<string, { image: string; alt: string }> }>
253267
}
254268

-85.3 KB
Binary file not shown.
-78.7 KB
Binary file not shown.
-83.3 KB
Binary file not shown.
-83.1 KB
Binary file not shown.
-64.1 KB
Binary file not shown.
-64 KB
Binary file not shown.
-87.9 KB
Binary file not shown.
-61.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)