Skip to content

feat: add OpenGraph image generation - #109

Open
Princesseuh wants to merge 12 commits into
mainfrom
claude/opengraph-image-generation-ro9lqm
Open

feat: add OpenGraph image generation#109
Princesseuh wants to merge 12 commits into
mainfrom
claude/opengraph-image-generation-ro9lqm

Conversation

@Princesseuh

Copy link
Copy Markdown
Member

What does this change?

  • Adds ctx.assets.add_opengraph_image(svg), a built-in way to generate OpenGraph images from an SVG string. The SVG is rendered to a PNG at build time using resvg.
  • Returns an OpenGraphImage with url(), width(), height(), and render() — the latter emits the <meta property="og:image"> tags. As with images, referencing the result in the page is opt-in; the image is generated whether or not render() is called.
  • Locked behind the new og_image crate feature, enabled by default. resvg is only pulled in when the feature is on.
let og = ctx.assets.add_opengraph_image(
    r##"<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="630">
          <rect width="100%" height="100%" fill="#1a1a1a"/>
          <text x="60" y="330" fill="white" font-size="72">Hello, world!</text>
        </svg>"##,
)?;

html! { head { (og.render()) } }

The generated PNG is materialized on disk and registered as a regular image asset, so it flows through the existing asset copy, hashing, caching, and stale-cleanup pipeline with no changes to build.rs.

Note: resvg renders SVG, not arbitrary HTML (HTML would need a browser/layout engine). SVG is easy to produce from maud/format!, so the API takes an SVG string.

How is it tested?

  • Unit tests in opengraph.rs: asset creation and PNG output, emitted meta tags, content-hash dedup (same SVG → same URL/file), and error on invalid SVG.
  • Verified end-to-end with a real coronate build: the PNG is written to the output dir (valid 1200×630), the og:image URL in the rendered HTML matches the file on disk, and it survives the bundling/substitution pass.
  • Full existing suite passes with --all-features, --no-default-features, and --features maud; clippy is clean in each configuration.

How is it documented?

  • Rustdoc on the module, OpenGraphImage, and add_opengraph_image, including a usage example (doctest).
  • A Sampo changeset (cargo/maudit: minor).
  • The kitchen-sink example is updated to generate and reference an OpenGraph image.

Generated by Claude Code

Add a built-in feature to generate OpenGraph images from an SVG string,
rendered to a PNG at build time via resvg. Available through
ctx.assets.add_opengraph_image, returning an OpenGraphImage whose
render() emits the og:image meta tags (opt-in, like images).

Locked behind the og_image crate feature, enabled by default.
@netlify

netlify Bot commented Jul 17, 2026

Copy link
Copy Markdown

Deploy Preview for maudit-framework ready!

Name Link
🔨 Latest commit 87e4ecf
🔍 Latest deploy log https://app.netlify.com/projects/maudit-framework/deploys/6a711a88b32b020008fa651e
😎 Deploy Preview https://deploy-preview-109--maudit-framework.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions Bot added crt:maudit Changes in Maudit crate. examples labels Jul 17, 2026
When BuildOptions::base_url is set, OpenGraphImage::url (and the tags from
render()) now produce an absolute URL, which is what OpenGraph consumers
expect. Falls back to a root-relative URL when base_url is unset.
Relative og:image URLs aren't reliably honored by OpenGraph consumers, so
add_opengraph_image now errors when BuildOptions::base_url is unset instead
of emitting a broken relative URL.
add_opengraph_image now takes an OpenGraphSource: either an inline SVG
string (dynamic) or an existing Image (static). SVG images are rendered to
a PNG; raster images are referenced as-is with the matching og:image:type.
Dimensions are omitted for resized rasters, where the source size no longer
matches the output.
@github-actions github-actions Bot added the crt:cli Changes in Maudit's CLI crate. label Jul 21, 2026
@github-actions github-actions Bot added crt:macros Changes in Maudit's macros crate crt:oubli Changes in Oubli crate. labels Aug 3, 2026
@github-actions github-actions Bot added the website Improvements or additions to documentation label Aug 3, 2026
@github-actions github-actions Bot added the devops Changes in the workflow/ actions/ linters/ releases. label Aug 3, 2026
@Princesseuh
Princesseuh force-pushed the claude/opengraph-image-generation-ro9lqm branch from 70e6954 to 87e4ecf Compare August 3, 2026 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

crt:cli Changes in Maudit's CLI crate. crt:macros Changes in Maudit's macros crate crt:maudit Changes in Maudit crate. crt:oubli Changes in Oubli crate. devops Changes in the workflow/ actions/ linters/ releases. examples website Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant