Skip to content

feat: add per-page Open Graph images#196

Open
rileychh wants to merge 3 commits into
mainfrom
og-images
Open

feat: add per-page Open Graph images#196
rileychh wants to merge 3 commits into
mainfrom
og-images

Conversation

@rileychh

@rileychh rileychh commented Jun 9, 2026

Copy link
Copy Markdown
Member

變更內容

Closes #127.
在建置階段為每個路由產生專屬的 Open Graph 預覽圖。

  • 使用 nuxt-og-image(Takumi renderer)在 nuxt generate 時輸出 PNG。
  • 議程頁:卡片含標題、講者、議程室與時間。
  • 其他頁面:使用 Default 樣板。
  • 議程圖片 zh / en 雙語皆預先產生。

字型與 CJK

  • 透過 @nuxt/fonts 載入 Noto Sans SC / TC / JP / KR (皆 weight 400)。
  • SC 為主要字型:Takumi 每個 script run 只選一種字型,SC 漢字涵蓋最廣 (簡繁皆以正確字形呈現)。
  • weight 僅 400(700 字重的 CJK 會被 Takumi 渲染污損)。
  • 加入 @iconify-json/noto 完整支援 emoji(模組預設只內建約 100 個)。

建置

  • build script 以 cross-env 將 heap 提高到 8 GB (4 套 CJK 字型 + 約 670 張圖片)。
  • nitro.prerender.failOnError: false 容忍 Pretalx API 偶發 500。
  • 移除全站固定的 og:image / twitter:image,改由模組逐頁注入。

建置過程會出現 Could not resolve font "Segoe UI" for OG images. 等找不到字體的錯誤,這是因為 UnoCSS preset-wind4 包含這些字體,但 nuxt-og-imageisSystemFont() 誤以為他們是外部字體而不是系統 fallback。這類警告可以安全的忽略。

樣式為何止於 inline style + 常數 (無法再進一步重構)

兩個樣板共用的色彩、字型、Logo path 與基礎版面已抽到 app/components/OgImage/theme.ts,以 inline :style 套用。Takumi renderer 的限制讓 CSS class 或共用 CSS 檔無法運作。實測結果:

做法 結果
inline :style + theme.ts 常數 正常
主題色 class(bg-primary-800) renderer timeout
共用檔 <style src="./og.css"> 被忽略
<script setup>import './og.css' 被忽略

原因:unocss-preset-theme 以 CSS 變數(var(--primary-800))定義主題色,但靜態 renderer 取不到變數定義而卡住逾時;且 Takumi 只讀 inline :style、inline <style> 文字與編譯後的 utility class,從不讀取外部或 JS 匯入的 CSS 檔。因此唯一同時「能共用又能正確渲染」的方式就是 JS/TS 常數。

驗證

  • 已讀取產出的 PNG 確認簡體、繁體、日文、emoji 與英文字降部皆正常,Logo 為 cp-green。
  • 請 reviewer 確認這樣的臨時版面在主視覺出來之前沒有問題

一些範例:

中文文章 英文文章
c_Default,title_~5Lqk6YCa,subtitle_~5YmN5b6AIENPU0NVUCAyMDI2IHggVWJ1Q29uIEFzaWEg5rS75YuV5Zyw6bue4oCU4oCU5ZyL56uL6Ie654Gj56eR5oqA5aSn5a2455qE5Lqk6YCa5pa55byP44CC,p_Ii90cmFuc3BvcnRhdGlvbiI c_Default,title_Transportation,subtitle_How+to+reach+the+COSCUP+2026+x+UbuCon+Asia+venue+at+National+Taiwan+University+of+Science+and+Technology ,p_Ii9lbi90cmFuc3BvcnRhdGlvbiI
預設圖片 含 Emoji 的議程
c_Default c_Session,title_~4pqhTGlnaHRuaW5nIHRhbGvimqEgWCAgQ2xvc2luZyBEYXkgMg,speakers_COSCUP+Team,room_RB105,time_~MTY6MTUgfiAxNzowMA,p_Ii9lbi9zZXNzaW9uL1ZCTFhZOSI

Summary by CodeRabbit

  • New Features

    • Added site-wide and page-specific Open Graph images for better link previews across the site.
    • Introduced dedicated preview layouts for general pages and session pages, including session details like speakers, room, and time.
    • Enabled English session routes to be pre-rendered alongside the default routes.
  • Bug Fixes

    • Improved build and metadata settings to help prevent rendering issues and ensure cleaner social sharing information.

@rileychh rileychh requested review from a team and Copilot June 9, 2026 10:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds build-time, per-route Open Graph image generation for the Nuxt site (including session pages with agenda-specific cards), replacing the previous site-wide static og:image/twitter:image approach and ensuring images are produced during nuxt generate.

Changes:

  • Integrates nuxt-og-image (Takumi renderer) and adds OG templates (Default and Session) plus per-page defineOgImage(...) usage.
  • Extends prerendering to include bilingual session detail routes (/session/:id and /en/session/:id) and relaxes Nitro prerender error handling.
  • Adds build/runtime dependencies and build script changes to support large-scale OG image generation (fonts, renderer deps, increased Node heap).

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pnpm-lock.yaml Locks newly added OG-image, renderer, font, and build tooling dependencies.
package.json Adds nuxt-og-image + renderer deps; increases build heap via cross-env in build script.
nuxt.config.ts Registers modules, configures fonts for OG rendering, disables Nitro prerender fail-on-error, removes global static og/twitter image meta.
app/app.vue Adds site-wide fallback defineOgImage('Default').
app/pages/session.vue Prerenders both zh (default) and /en session detail routes.
app/pages/session/[id].vue Defines per-session OG images using the Session template with fetched session metadata.
app/pages/[...slug].vue Defines per-content-page OG images using the Default template populated from content metadata.
app/components/OgImage/theme.ts Introduces shared inline-style constants for OG image templates.
app/components/OgImage/Default.takumi.vue Implements default OG card template layout for non-session pages.
app/components/OgImage/Session.takumi.vue Implements session OG card template layout (title/speakers/room/time).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/components/OgImage/Session.takumi.vue
Comment thread app/components/OgImage/Default.takumi.vue
@rileychh rileychh linked an issue Jun 9, 2026 that may be closed by this pull request
Base automatically changed from page-descriptions to main June 14, 2026 06:20
@rileychh-dokploy-coscup

rileychh-dokploy-coscup Bot commented Jun 15, 2026

Copy link
Copy Markdown

Dokploy Preview Deployment

Name Status Preview Updated (UTC)
Nuxt ✅ Done Preview URL 2026-06-15T08:35:09.879Z

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4003c3cb20

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread nuxt.config.ts Outdated
pan93412
pan93412 previously approved these changes Jun 17, 2026
Comment thread app/components/OgImage/theme.ts
mirumodapon
mirumodapon previously approved these changes Jun 26, 2026

@mirumodapon mirumodapon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mirumodapon

Copy link
Copy Markdown
Collaborator

再麻煩幫我解一下衝突喔

rileychh added 2 commits June 29, 2026 09:03
Generate a branded OG image per route at build time with nuxt-og-image
(Takumi renderer). Sessions render a card with title, speakers, room, and
time; every other page uses a Default template. Session images are
prerendered for both zh and en.

- Add @nuxt/fonts with Noto Sans SC/TC/JP/KR (weight 400) for CJK glyph
  coverage. SC is primary: Takumi selects one font per script run rather
  than per glyph, and SC has the widest Han coverage (Simplified and
  Traditional, each in its correct form).
- Add @iconify-json/noto for full emoji coverage (the module bundles only
  ~100 by default).
- Raise the build heap to 8 GB via cross-env for 4 CJK fonts + ~670 images.
- Set nitro.prerender.failOnError: false to tolerate transient Pretalx 500s.
- Drop the static site-wide og:image/twitter:image meta; the module now
  injects both per page.
- Share the colors, font-family chain, logo path, and base card layout
  across both templates via a small app/components/OgImage/theme.ts module.
Unbounded parallel prerendering spiked to ~12.6GB RSS during the
session OG card render burst, OOM-killing the 16GB CI runner
non-deterministically. Capping concurrency to 4 bounds the peak to
~10.2GB (independent of session count) while keeping build time flat.
@rileychh

Copy link
Copy Markdown
Member Author

我先處理沒辦法在本機上編譯,還有 failOnError: false 吞掉太多非 OG 錯誤的問題,再一起推上來。

- Disable Nuxt payload extraction: nuxt-og-image's isInternalRoute only skips
  paths starting with "/_", so under baseURL "/2026" it processes the
  "/2026/.../_payload.json" routes as real pages. defineOgImage on session
  detail pages then made the renderer return no response (500) for those
  payload routes during prerender.
- Drop the prerender failOnError override now that payload routes build
  cleanly, restoring strict deploy-time error checking for the static build.
- Pass defineOgImage props via a variable: under the repo's strict
  vueCompilerOptions, the inline object literal tripped TS2353 excess-property
  checks because nuxt-og-image's ReactiveComponentProps resolves to {}.
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds OG image generation support by introducing shared theme constants and two new OG image components (Default.takumi.vue, Session.takumi.vue). Wires defineOgImage calls into app.vue, [...slug].vue, and session/[id].vue. Updates Nuxt config with font, site URL, prerender concurrency, and payload extraction settings, and adds corresponding dependencies.

Changes

OG Image Generation

Layer / File(s) Summary
OG theme constants and dependencies
app/components/OgImage/theme.ts, package.json
Exports shared color tokens, logo SVG config, font family, and base card style. Adds satori, @resvg/resvg-js, @nuxt/fonts, @iconify-json/noto, @takumi-rs/core as dependencies; increases build memory limit via cross-env NODE_OPTIONS.
Default and Session OG image components
app/components/OgImage/Default.takumi.vue, app/components/OgImage/Session.takumi.vue
Default.takumi.vue renders a card with title/subtitle props. Session.takumi.vue renders session metadata (title, speakers, room, time) with conditional display of speakers and room/time lines joined by ·. Both use shared theme constants.
defineOgImage wiring in pages and app root
app/app.vue, app/pages/[...slug].vue, app/pages/session/[id].vue, app/pages/session.vue
Registers site-wide fallback defineOgImage('Default') in app.vue. Passes page title/description to defineOgImage in [...slug].vue. Passes session fields to defineOgImage('Session') in session/[id].vue. Extends prerenderRoutes in session.vue to emit both /session/{id} and /en/session/{id} per session.
Nuxt config: fonts, site, prerender, meta
nuxt.config.ts
Adds @nuxt/fonts module with Noto Sans CJK families at weight 400. Sets site.url, site.name, and i18n.baseUrl. Configures nitro prerender concurrency: 4 and disables payloadExtraction. Updates head meta to Twitter card tags; removes static og:image/twitter:image entries.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 A card for each session, a logo in place,
With satori and fonts to style every face.
The rabbit hops in with a Default and Session,
Each page gets its image — no more impression of "none"!
defineOgImage called, the meta is set,
The fluffiest OG cards you've seen on the net! 🖼️

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding per-page Open Graph images.
Linked Issues check ✅ Passed The PR satisfies #127 by adding default and session OG image support, page wiring, and build-time generation.
Out of Scope Changes check ✅ Passed The changes are aligned with the OG image feature and supporting build/config updates; no unrelated additions stand out.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch og-images

Comment @coderabbitai help to get the list of available commands.

@rileychh

rileychh commented Jun 29, 2026

Copy link
Copy Markdown
Member Author

Note

留言由 Claude 輔助撰寫。

已 rebase 並將 failOnError 改回嚴格模式(移除 failOnError: false),恢復靜態建置時的部署前錯誤把關。

先前之所以需要 failOnError: false,真正原因是 nuxt-og-image 的 isInternalRoute 只會略過開頭為 /_ 的路徑,但本站 baseURL/2026,所以 /2026/.../_payload.json 這類 payload 路由不會被略過,會被當成一般頁面處理。議程詳細頁呼叫 defineOgImage() 後,這些 payload 路由在預先渲染時會讓 renderer 回傳空回應,進而產生 500(共 ~40 條 /session/:id/_payload.json 路由),逼得只能關掉 failOnError 才能完成建置。

修正方式是停用 Nuxt 的 payload extraction (experimental.payloadExtraction: false),不再產生 _payload.json 路由,該問題便無從觸發,建置即可在嚴格模式下通過。本站頁面多為客戶端渲染、資料本來就透過 API 取得,關閉 payload extraction 的影響極小 (payload 改為內嵌於各 HTML) 建置時間反而從約 70 秒降到約 31 秒。

參考: https://nuxt.com/docs/4.x/guide/going-further/experimental-features#payloadextraction

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dadf2c6337

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +23 to +24
width: '100%',
height: '100%',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep padded OG cards within the canvas

Both OG templates spread this base style and then add 72–80px of padding on the same root element. Because these templates use inline styles rather than a CSS reset/preflight, the root keeps the default content-box sizing, so width: '100%'/height: '100%' plus padding renders larger than the 1200x600 OG canvas and can clip the footer bar or session metadata at the bottom/right; add boxSizing: 'border-box' to the shared base style.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@nuxt.config.ts`:
- Around line 102-106: Remove the global experimental payloadExtraction override
in nuxt.config.ts so the site no longer disables payload splitting everywhere.
Update the Nuxt config around the experimental block to stop forcing
payloadExtraction false, and rely on nuxt-og-image 6.5.2’s baseURL-aware
behavior instead; keep the config change localized to the existing experimental
settings in the Nuxt configuration.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e3a078a6-eab8-40c6-9b8e-7bf187b8b971

📥 Commits

Reviewing files that changed from the base of the PR and between 5df49b5 and dadf2c6.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (9)
  • app/app.vue
  • app/components/OgImage/Default.takumi.vue
  • app/components/OgImage/Session.takumi.vue
  • app/components/OgImage/theme.ts
  • app/pages/[...slug].vue
  • app/pages/session.vue
  • app/pages/session/[id].vue
  • nuxt.config.ts
  • package.json

Comment thread nuxt.config.ts
Comment on lines +102 to +106
experimental: {
// nuxt-og-image breaks payload-route rendering on pages that call defineOgImage
// under baseURL "/2026" (its isInternalRoute misses "/2026/.../_payload.json"),
// making the renderer return no response (500). Disable payload extraction.
payloadExtraction: false,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

Does nuxt-og-image6.5.2 on Nuxt 4.4.x still requireexperimental.payloadExtraction = falsewhenapp.baseURLis a subpath like/2026, or is there a supported route-scoped workaround?

💡 Result:

As of nuxt-og-image version 6.5.2 running on Nuxt 4.4.x, setting experimental.payloadExtraction = false is no longer a documented or required workaround for handling app.baseURL subpaths. The module has received significant updates to its runtime configuration and path resolution logic [1][2][3], specifically improving support for custom baseURLs [4]. In modern versions of the module, the runtime configuration correctly consumes the app's baseURL [1], ensuring that OG image paths are generated with the correct base prefix automatically. If you are encountering issues with OG image path resolution or prerendering while using a subpath (e.g., /2026), ensure you are using the latest version of the module and that your site's baseURL is configured correctly in your nuxt.config.ts: export default defineNuxtConfig({ app: { baseURL: '/2026/', // Ensure trailing slash is included for consistency }, }) There is no supported route-scoped workaround for payload extraction because the issue you are referencing historically stemmed from how Nuxt itself handled base paths during static generation [5][6], which has been largely resolved in later Nuxt versions. If you face persistent 404s or path resolution errors, it is recommended to verify your environment configuration rather than disabling payload extraction, as disabling it may negatively impact performance and functionality [7].

Citations:


🏁 Script executed:

git ls-files nuxt.config.ts package.json pnpm-lock.yaml package-lock.json yarn.lock README.md docs 2>/dev/null

Repository: COSCUP/2026

Length of output: 202


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n## files\n'
git ls-files nuxt.config.ts package.json pnpm-lock.yaml package-lock.json yarn.lock README.md docs 2>/dev/null || true

printf '\n## search\n'
rg -n "nuxt-og-image|payloadExtraction|baseURL|app\.baseURL|site\.url|site\.name" nuxt.config.ts package.json README.md docs 2>/dev/null || true

Repository: COSCUP/2026

Length of output: 916


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '1,220p' nuxt.config.ts | cat -n

Repository: COSCUP/2026

Length of output: 7430


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '1,140p' package.json | cat -n

Repository: COSCUP/2026

Length of output: 2103


🌐 Web query:

nuxt-og-image 6.5.2 payloadExtraction baseURL subpath defineOgImage Nuxt 4.4.8

💡 Result:

In nuxt-og-image v6.5.2, configuration and behavior regarding base paths and payloads are handled through Nuxt's standard runtime configuration and internal module routing. Regarding the technical aspects mentioned: 1. payloadExtraction: While not explicitly defined as a top-level module option in documentation, nuxt-og-image relies on Nuxt's built-in payload extraction (used during build/prerendering). The module automatically handles the necessary context for generated images [1][2]. 2. baseURL and subpaths: When deploying a Nuxt application with a custom baseURL (e.g., set via app.baseURL in nuxt.config.ts), nuxt-og-image dynamically respects this configuration [1][3]. The module ensures that internal routes (such as the OG image generation endpoints, typically prefixed with /_og/) are correctly resolved relative to the defined base path [1][4]. If your application is hosted behind a reverse proxy, you must ensure the proxy correctly forwards the subpath to your Nuxt server to prevent 404 errors for these internal routes [5]. 3. defineOgImage: This composable remains the primary API for defining Open Graph images on a per-page basis [6][7]. In version 6.5.2, it has been refined to better support runtime configuration and path resolution [8][1]. You can use it as follows: defineOgImage({ component: 'MyComponent', props: { title: 'Hello' } }) For performance, if you are using an existing static image instead of generating one, use useSeoMeta instead to bypass the OG image generation logic: useSeoMeta({ ogImage: '/my-static-image.png' }) 4. Nuxt 4.4.8 Compatibility: nuxt-og-image v6.5.2 is designed to be compatible with modern Nuxt 4 releases. Ensure your environment matches the Nuxt 4 configurations for app.baseURL [3] and that no conflicting middleware is intercepting the /_og/ route path [4]. Top results: [1][3][7][4]

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n "payloadExtraction|nuxt-og-image|defineOgImage|baseURL|/2026" README.md nuxt.config.ts pnpm-lock.yaml

Repository: COSCUP/2026

Length of output: 1011


Remove the global payloadExtraction: false workaround. nuxt-og-image 6.5.2 already respects app.baseURL, so this disables payload splitting for the whole site unnecessarily.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@nuxt.config.ts` around lines 102 - 106, Remove the global experimental
payloadExtraction override in nuxt.config.ts so the site no longer disables
payload splitting everywhere. Update the Nuxt config around the experimental
block to stop forcing payloadExtraction false, and rely on nuxt-og-image 6.5.2’s
baseURL-aware behavior instead; keep the config change localized to the existing
experimental settings in the Nuxt configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

og image 支援

4 participants