Oriel — AI & technology worth noticing, every day.

Open Graph images with Astro and Typst

Web page · https://eaj.no/posts/open-graph-images-with-typst

First seen by Oriel on .

AI summary

The article shows how to generate per-post Open Graph PNGs at Astro build time by compiling a parameterized Typst template, then cache-bust them based on their content.

  • A Typst template renders a 1200-by-630-point image, taking each post title through the CLI's `--input` option.
  • Astro's dynamic `src/pages/posts/[id]/og.png.ts` route uses `getStaticPaths` and the Content Collection API to generate one image per post.
  • The route invokes `typst compile` with PNG output at 144 PPI and returns the bytes with an `image/png` content type.
  • A SHA-256 hash of the template and title, truncated to 10 hexadecimal characters, changes the image URL only when its content changes.
  • The approach replaces manually selected stock images with build-time generated cards; social platforms may cache older images, motivating the content-based cache key.

#astro #typst #open graph #static site generation

Generated by gpt-5.6-sol. Check the original for details.

Metric trends

Last 30 days · Up to 120 recorded samples per source and metric, with reposts kept separate · First and latest retained

Points

Score reported by the source.

  • Lobsters: 47, latest observation ; +46 over observed period since

Comments

Comment count reported by the source.

  • Lobsters: 13, latest observation ; +13 over observed period since

Aliases

SourceExternal IDURL
Lobstersgj5obqhttps://eaj.no/posts/open-graph-images-with-typst/ Read discussion