Skip to content

Commit 24827cb

Browse files
committed
feat(seo): 🚀 generated social cards (og:image) with Takumi
Page heads - Every page with a title emits og:title, og:description, og:type, og:site_name, og:url, og:locale, og:image (with type, size and alt) and twitter:card; `canonical` and `openGraph` are accepted by plugin route heads, and delivered content pages pass their canonical URL and card. - `metadata.ogImage` sets the default image (the generated site card, a URL, or `false`). Cards - The API draws 1200 × 630 PNG cards with Takumi on Node.js and Cloudflare Workers, with bundled Geist fonts (Latin, Latin Extended, Cyrillic) and no network access: content (`/delivery/og/{slug}` per content type), member profiles (`/og/users/{nameCode}`) and the site (`/og/site`). - Versioned URLs (`v`) are cached for a year, stale ones for an hour; only public, visible records and existing members are drawn. - Content Engine: `delivery.seo.openGraph.imageField` is the cover behind the card (`generateImage: false` uses it as og:image instead); covers and profile covers are read from storage, and their file id is part of the card version. - `ogImage` API config: enabled, fonts, theme, template, templates per content type, version and `logo` (SVG or data URI; `VITNODE_LOGO_SVG` and `VITNODE_ICON_SVG` ship with core); plugins register templates with `buildApiPlugin({ ogImageTemplates })`. Design (decided from prototype rounds of 25+ variants) - Pull quote: the logo heads the card, the description is the quote, the title signs it; profiles quote the headline and sign with name and avatar. - The cover fills the right 820 px, solid under the quote column, then fades in along a smoothstep curve; drawn at 82% brightness. - Theme: the web app's dark tokens. - Rejected: Quiet, Editorial, Brand, Split, Terminal, Aurora, Poster, Brutal, Hexgrid, Watermark, Broadcast, Swiss, Thread; quote riffs Light, Mark, Rule, Speaker, Brand; cover layouts Split, Inset, Band, Duotone; a blurred full-bleed backdrop (hid the cover) and a logo on the cover. Plugins and apps - Blog uses its cover; forum topics and newsroom events get cards. The demo apps use the VitNode wordmark. - Docs: new Social images page; Content Engine SEO, route module and configuration pages updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CnAiFbNcH9MjiCNhLJu5hq
1 parent c3afc9c commit 24827cb

51 files changed

Lines changed: 2628 additions & 76 deletions

Some content is hidden

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

‎apps/api/src/vitnode.api.config.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { DiscordSSOApiPlugin } from "@vitnode/api/adapters/sso/discord";
33
import { FacebookSSOApiPlugin } from "@vitnode/api/adapters/sso/facebook";
44
import { GoogleSSOApiPlugin } from "@vitnode/api/adapters/sso/google";
55
import { coreRelations } from "@vitnode/api/database/relations";
6+
import { VITNODE_LOGO_SVG } from "@vitnode/api/lib/og-image/vitnode-logo";
67
// import { LocalStorageAdapter } from "@vitnode/api/adapters/storage/local";
78
import { buildApiConfig } from "@vitnode/api/vitnode.config";
89
import { blogApiPlugin } from "@vitnode/blog/config.api";
@@ -187,4 +188,8 @@ export const vitNodeApiConfig = buildApiConfig({
187188
title: "VitNode API",
188189
shortTitle: "VitNode",
189190
},
191+
// The VitNode wordmark on every social card, drawn from SVG.
192+
ogImage: {
193+
logo: { svg: VITNODE_LOGO_SVG, wordmark: true },
194+
},
190195
});

‎apps/web/content/docs/content-engine/seo.mdx‎

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
22
title: SEO
3-
description: Set the title, meta description, noindex, hreflang and sitemap entries of VitNode Content Engine record pages with delivery.seo and delivery.sitemap.
3+
description: Set the title, meta description, social image, noindex, hreflang and sitemap entries of VitNode Content Engine record pages with delivery.seo and delivery.sitemap.
44
icon: SearchCheck
55
---
66

77
import { ImgDocs } from "@/components/fumadocs/img";
88
import blogSeoSheet from "./seo-blog-sheet.webp";
99

10-
Once a content type has [public pages](/docs/content-engine/public-pages), `delivery.seo` decides which fields fill each page's `<title>`, meta description and `robots` tag, and `delivery.sitemap` lists the pages for crawlers. You name fields; the Content Engine reads them from every published record, so editors never fill in a separate SEO form unless you give them one.
10+
Once a content type has [public pages](/docs/content-engine/public-pages), `delivery.seo` decides which fields fill each page's `<title>`, meta description, Open Graph tags and `robots` tag, and `delivery.sitemap` lists the pages for crawlers. You name fields; the Content Engine reads them from every published record, so editors never fill in a separate SEO form unless you give them one.
1111

1212
The examples use `newsroom.story` from the newsroom plugin and `blog.post` from the blog plugin, which is localized.
1313

@@ -70,6 +70,8 @@ delivery: {
7070
| `noIndexField` | boolean, not localized | `robots` tag and sitemap, see [noindex](#hide-a-record-from-search-engines) |
7171
| `openGraph.titleField` | text | Open Graph title, falls back to the page title |
7272
| `openGraph.descriptionField` | text, textarea, richText | Open Graph description, falls back to the page description |
73+
| `openGraph.imageField` | file, single, not localized | The cover behind the card, see [Social images](#social-images) |
74+
| `openGraph.generateImage` | boolean, default `true` | `false` uses the cover itself as `og:image`, see [Social images](#social-images) |
7375

7476
Every field you name must also be in `publicApi.fields`, because the page shows it to anyone. Leave one out and the definition throws at startup with `... which is not in publicApi.fields`. A field inside a group works (`"seo.title"`). A field inside a repeatable does not, since a page has one title, not a list of them.
7577

@@ -80,6 +82,7 @@ delivery: {
8082
seo: {
8183
titleField: "title",
8284
descriptionField: "content",
85+
openGraph: { imageField: "coverImage" },
8386
},
8487
},
8588
```
@@ -97,19 +100,44 @@ The blog plugin's own article editor checks the fields this rule reads in its **
97100

98101
## What reaches the page head
99102

100-
The page's `head` calls `contentDeliveryPageHead` with the resolve route's answer, as shown in [Write the page](/docs/content-engine/public-pages#write-the-page). This is what the HTML gets today:
103+
The page's `head` calls `contentDeliveryPageHead` with the resolve route's answer, as shown in [Write the page](/docs/content-engine/public-pages#write-the-page). This is what the HTML gets:
101104

102-
| Tag | Rendered |
103-
| ------------------------------------------- | ------------------------------------------- |
104-
| `<title>` | Yes, followed by the site title (`- VitNode`) |
105-
| `<meta name="description">` | Yes, at most 160 characters |
106-
| `<meta name="robots">` | Only for a no-index record |
107-
| `<link rel="canonical">` and `hreflang` links | Only for a localized content type |
108-
| `og:title`, `og:description` | No |
105+
| Tag | Rendered |
106+
| --------------------------------------------- | ------------------------------------------------------------------------ |
107+
| `<title>` | Yes, followed by the site title (`- VitNode`) |
108+
| `<meta name="description">` | Yes, at most 160 characters |
109+
| `<meta name="robots">` | Only for a no-index record |
110+
| `<link rel="canonical">` | Yes. A localized type adds the `hreflang` links |
111+
| `og:title`, `og:description`, `og:type` | Yes, `og:type` is `article`. From `openGraph` when set, else the page's |
112+
| `og:url`, `og:site_name`, `og:locale` | Yes |
113+
| `og:image` and its size, type and alt | Yes, see [Social images](#social-images) |
114+
| `twitter:card` | `summary_large_image` with an image, `summary` without |
109115

110-
<Callout type="warn">
111-
The resolve route returns `openGraph` and `canonicalPath` for every record, but nothing turns them into tags yet. A nonlocalized type such as `newsroom.story` gets no canonical link, and no content type gets Open Graph tags. A plugin page cannot add them either, because its `head` only accepts `title`, `description`, `robots` and `alternates`. Keep `openGraph` in your definition so the data is ready, and read it from the resolve route if you render pages outside VitNode.
112-
</Callout>
116+
## Social images
117+
118+
With `delivery.seo.openGraph` set, a record page gets an `og:image`, the picture link previews show. The API draws it as a 1200 × 630 card at `/delivery/og/{slug}`, next to the other delivery routes: the Open Graph description as a large quote, signed with the title. `openGraph: {}` is enough to get one.
119+
120+
- **A cover behind the card.** `openGraph.imageField` names a shared, single `field.file()` in `publicApi.fields`; the blog uses its cover. The card shows it on the right side, fading smoothly into the background, and keeps the quote in its own column so no word sits on the picture. Only an image a reader may open counts: a GIF, JPEG, PNG or WebP that no [attachment rule](/docs/content-engine/access-attachments) restricts. The API reads it from your storage, and a new cover gives the card a new URL.
121+
- **The cover on its own.** `generateImage: false` skips the card and uses the `imageField` image itself as `og:image`, with the file's alt text in the page's language. A record without a cover then falls back to the site image.
122+
123+
The resolve route reports the choice under `openGraph.image`:
124+
125+
```json
126+
"openGraph": {
127+
"title": "Hello Content Engine",
128+
"description": "A first story from the newsroom plugin, served by the public API and rendered on its own page.",
129+
"image": {
130+
"alt": "Hello Content Engine",
131+
"generated": true,
132+
"height": 630,
133+
"type": "image/png",
134+
"url": "http://localhost:3000/api/newsroom/content/stories/delivery/og/hello-content-engine?v=0k7ophq",
135+
"width": 1200
136+
}
137+
}
138+
```
139+
140+
Colours, fonts, templates per content type and caching are covered in [Social images](/docs/dev/social-images).
113141

114142
## Hide a record from search engines
115143

@@ -265,8 +293,11 @@ curl -s http://localhost:3000/stories/hello-content-engine | grep -oE '<title>[^
265293
```html
266294
<title>Hello Content Engine - VitNode</title>
267295
<meta content="A first story from the newsroom plugin, served by the public API and rendered on its own page." name="description"/>
296+
<link href="http://localhost:3000/stories/hello-content-engine" rel="canonical"/>
268297
```
269298

299+
The same page also carries the `og:*` tags and `twitter:card` from [What reaches the page head](#what-reaches-the-page-head).
300+
270301
Run the same command for `http://localhost:3000/blog/article/english-title` and you get its title, description and the four links from [Localized alternates](#localized-alternates-and-hreflang). The SVG logo's `<title>Logo VitNode</title>` may show up too; it is not page metadata.
271302

272303
Then ask the resolve route what the page was given, `openGraph` and `robots` included:

‎apps/web/content/docs/dev/configuration.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const vitNodeConfig = buildConfig({
5656
| Name | Type | Required | Default | Description |
5757
| :---------------- | :----------------------- | :------- | :------------- | :----------------------------------------------------------------------------------------------- |
5858
| `i18n` | object | Yes | - | Languages and locale routing. See [Languages & Localization](/docs/dev/i18n) |
59-
| `metadata` | object | Yes | - | Site title, used in page titles as `{page} - {shortTitle ?? title}` |
59+
| `metadata` | object | Yes | - | Site title, used in page titles as `{page} - {shortTitle ?? title}`. `metadata.ogImage` sets the default social image, see [Social images](/docs/dev/social-images) |
6060
| `plugins` | `buildPlugin()` results | Yes | - | The installed plugins' frontend factories. See [Enabled plugins](#enabled-plugins) |
6161
| `editor` | object | No | - | Settings shared by every `Editor` in the app |
6262
| `logo` | component | No | VitNode logo | The header logo. See [Logo](#logo) |

‎apps/web/content/docs/dev/meta.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"i18n",
2727
"navigation",
2828
"mobile-navigation",
29+
"social-images",
2930
"performance",
3031
"---Extend VitNode---",
3132
"widgets",

‎apps/web/content/docs/dev/routing/route-module.mdx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ Throw `notFound()` or `redirect()` from `@tanstack/react-router` to answer with
7979
| `description` | `string` | The `<meta name="description">`. |
8080
| `robots` | `'index, follow' \| 'noindex, follow' \| 'noindex, nofollow'` | What a crawler may do. `noindex, follow` keeps a filtered list out of the index while its links still count. |
8181
| `alternates` | `Record<string, string>` | Internal paths of the page in each language, for canonical and `hreflang` links. See [Advanced localized URLs](/docs/dev/i18n/localized-urls-advanced#hreflang-and-canonical-links). |
82+
| `canonical` | `string` | The canonical URL, absolute or a path on the site, for a page without `alternates`. Also becomes `og:url`. |
83+
| `openGraph` | `{ title?, description?, type?, image? }` | Overrides for link previews. `type` is `article`, `profile` or `website` (the default). `image` is `{ url, width?, height?, type?, alt? }`. See [Social images](/docs/dev/social-images). |
8284

83-
Return only these fields. VitNode turns them into the full set of tags with the app's site metadata.
85+
Return only these fields. VitNode turns them into the full set of tags with the app's site metadata. A page with a `title` also gets Open Graph and `twitter:card` tags, with the site's [social image](/docs/dev/social-images) when it sets no `openGraph.image`.
8486

8587
## Translated metadata
8688

25.8 KB
Loading

0 commit comments

Comments
 (0)