Skip to content

Commit d8c4b53

Browse files
Merge pull request #927 from aXenDeveloper/claude/serene-goodall-bkfce9
feat(seo): 🚀 generated social cards (og:image) with Takumi
2 parents a4c5f05 + a96117b commit d8c4b53

66 files changed

Lines changed: 3066 additions & 121 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: 4 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,7 @@ export const vitNodeApiConfig = buildApiConfig({
187188
title: "VitNode API",
188189
shortTitle: "VitNode",
189190
},
191+
ogImage: {
192+
logo: { svg: VITNODE_LOGO_SVG, wordmark: true },
193+
},
190194
});

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

Lines changed: 43 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 used as `og:image` with `generateImage: false`, 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: { generateImage: false, imageField: "coverImage" },
8386
},
8487
},
8588
```
@@ -97,19 +100,43 @@ 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+
The card never draws pictures from the record, only text on the site's colours. To share a record's own cover instead, name it in `openGraph.imageField` and set `generateImage: false`: the field is a shared, single `field.file()` in `publicApi.fields`, and the image itself becomes `og:image`, with the file's alt text in the page's language (the record's title when the file has none). Only an image a reader may open counts: a GIF, JPEG, PNG or WebP that no [attachment rule](/docs/content-engine/access-attachments) restricts. A record without a cover then falls back to the site card, drawn with its title and description. The blog plugin works this way.
121+
122+
The resolve route reports the choice under `openGraph.image`:
123+
124+
```json
125+
"openGraph": {
126+
"title": "Hello Content Engine",
127+
"description": "A first story from the newsroom plugin, served by the public API and rendered on its own page.",
128+
"image": {
129+
"alt": "Hello Content Engine",
130+
"generated": true,
131+
"height": 630,
132+
"type": "image/png",
133+
"url": "http://localhost:3000/api/newsroom/content/stories/delivery/og/hello-content-engine?v=0k7ophq",
134+
"width": 1200
135+
}
136+
}
137+
```
138+
139+
Colours, fonts, templates per content type and caching are covered in [Social images](/docs/dev/social-images).
113140

114141
## Hide a record from search engines
115142

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

298+
The same page also carries the `og:*` tags and `twitter:card` from [What reaches the page head](#what-reaches-the-page-head).
299+
270300
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.
271301

272302
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 and `metadata.twitterSite` the X handle, 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

30.5 KB
Loading

0 commit comments

Comments
 (0)