Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/api/src/vitnode.api.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DiscordSSOApiPlugin } from "@vitnode/api/adapters/sso/discord";
import { FacebookSSOApiPlugin } from "@vitnode/api/adapters/sso/facebook";
import { GoogleSSOApiPlugin } from "@vitnode/api/adapters/sso/google";
import { coreRelations } from "@vitnode/api/database/relations";
import { VITNODE_LOGO_SVG } from "@vitnode/api/lib/og-image/vitnode-logo";
// import { LocalStorageAdapter } from "@vitnode/api/adapters/storage/local";
import { buildApiConfig } from "@vitnode/api/vitnode.config";
import { blogApiPlugin } from "@vitnode/blog/config.api";
Expand Down Expand Up @@ -187,4 +188,7 @@ export const vitNodeApiConfig = buildApiConfig({
title: "VitNode API",
shortTitle: "VitNode",
},
ogImage: {
logo: { svg: VITNODE_LOGO_SVG, wordmark: true },
},
});
56 changes: 43 additions & 13 deletions apps/web/content/docs/content-engine/seo.mdx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
title: SEO
description: Set the title, meta description, noindex, hreflang and sitemap entries of VitNode Content Engine record pages with delivery.seo and delivery.sitemap.
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.
icon: SearchCheck
---

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

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.
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.

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

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

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.

Expand All @@ -80,6 +82,7 @@ delivery: {
seo: {
titleField: "title",
descriptionField: "content",
openGraph: { generateImage: false, imageField: "coverImage" },
},
},
```
Expand All @@ -97,19 +100,43 @@ The blog plugin's own article editor checks the fields this rule reads in its **

## What reaches the page head

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:
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:

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

<Callout type="warn">
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.
</Callout>
## Social images

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.

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.

The resolve route reports the choice under `openGraph.image`:

```json
"openGraph": {
"title": "Hello Content Engine",
"description": "A first story from the newsroom plugin, served by the public API and rendered on its own page.",
"image": {
"alt": "Hello Content Engine",
"generated": true,
"height": 630,
"type": "image/png",
"url": "http://localhost:3000/api/newsroom/content/stories/delivery/og/hello-content-engine?v=0k7ophq",
"width": 1200
}
}
```

Colours, fonts, templates per content type and caching are covered in [Social images](/docs/dev/social-images).

## Hide a record from search engines

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

The same page also carries the `og:*` tags and `twitter:card` from [What reaches the page head](#what-reaches-the-page-head).

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.

Then ask the resolve route what the page was given, `openGraph` and `robots` included:
Expand Down
2 changes: 1 addition & 1 deletion apps/web/content/docs/dev/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const vitNodeConfig = buildConfig({
| Name | Type | Required | Default | Description |
| :---------------- | :----------------------- | :------- | :------------- | :----------------------------------------------------------------------------------------------- |
| `i18n` | object | Yes | - | Languages and locale routing. See [Languages & Localization](/docs/dev/i18n) |
| `metadata` | object | Yes | - | Site title, used in page titles as `{page} - {shortTitle ?? title}` |
| `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) |
| `plugins` | `buildPlugin()` results | Yes | - | The installed plugins' frontend factories. See [Enabled plugins](#enabled-plugins) |
| `editor` | object | No | - | Settings shared by every `Editor` in the app |
| `logo` | component | No | VitNode logo | The header logo. See [Logo](#logo) |
Expand Down
1 change: 1 addition & 0 deletions apps/web/content/docs/dev/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"i18n",
"navigation",
"mobile-navigation",
"social-images",
"performance",
"---Extend VitNode---",
"widgets",
Expand Down
4 changes: 3 additions & 1 deletion apps/web/content/docs/dev/routing/route-module.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ Throw `notFound()` or `redirect()` from `@tanstack/react-router` to answer with
| `description` | `string` | The `<meta name="description">`. |
| `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. |
| `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). |
| `canonical` | `string` | The canonical URL, absolute or a path on the site, for a page without `alternates`. Also becomes `og:url`. |
| `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). |

Return only these fields. VitNode turns them into the full set of tags with the app's site metadata.
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`.

## Translated metadata

Expand Down
Binary file added apps/web/content/docs/dev/social-images-card.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading