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
35 changes: 32 additions & 3 deletions apps/web/content/docs/content-engine/seo.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ The resolve route reports the choice under `openGraph.image`:
}
```

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

## Hide a record from search engines

Expand Down Expand Up @@ -176,7 +176,36 @@ delivery: {

## Sitemap

`delivery.sitemap` adds a public route that lists every published URL of the content type, oldest record first. Pass `true` or `{ changeFrequency, priority }`. It needs `publication: true`, since a sitemap lists only what readers can reach.
`delivery.sitemap` puts every published record of the content type in the site's `/sitemap.xml`. Pass `true` or `{ changeFrequency, priority }`. It needs `publication: true`, since a sitemap lists only what readers can reach.

```ts title="plugins/newsroom/src/content/story.ts"
delivery: {
sitemap: { changeFrequency: 'weekly', priority: 0.7 }, // [!code ++]
},
```

That is all a plugin author writes. When an app turns on [site SEO](/docs/dev/seo/setup), its build finds every content type with `delivery.sitemap` in the configured plugins and writes them to `src/sitemap-sources.gen.ts`. `withSeo` then reads each one's route as a guest and publishes one child file per language, such as `/sitemap-stories-1.xml` or `/sitemap-blog-pl-1.xml`. A content type whose public API path is shared with another plugin's gets the plugin id in its file name, and two names that would still collide fail the build.

### Check that a record is listed

With the newsroom plugin and `seo: { indexing: true }`:

1. Publish a story, then open the index and the story file:

```bash
curl -s http://localhost:3000/sitemap.xml
curl -s http://localhost:3000/sitemap-stories-1.xml | grep hello-content-engine
```

The story's `<loc>` is there, with `<lastmod>`, `<changefreq>` and `<priority>`.

2. Set the story's `noIndexField` to `true` (`newsroom.story` calls it `noIndex`), or [hide](/docs/content-engine/content-visibility) the story, and run the second command again. It prints nothing: the change expired the file, and the new copy leaves the record out.

A translation appears in its own language's file only once it is published, and the XML is the same when a signed-in admin requests it.

### Read the sitemap route yourself

The generated sitemap reads a public route that every content type with `delivery.sitemap` gets. Use it directly when you assemble XML in an app that does not use `withSeo`.

```bash
curl "http://localhost:3000/api/newsroom/content/stories/delivery/sitemap?cursor=1&limit=1"
Expand Down Expand Up @@ -224,7 +253,7 @@ curl "http://localhost:3000/api/@vitnode/blog/content/blog/delivery/sitemap?loca
}
```

The app's `/sitemap.xml` does not read these routes for you, so add the entries where you build it. `contentSitemapXml` from `@vitnode/core/content` writes the XML:
To build the XML yourself, `contentSitemapXml` from `@vitnode/core/content` writes it:

```ts
import {
Expand Down
28 changes: 26 additions & 2 deletions apps/web/content/docs/dev/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ files, filled in with working defaults.
| File | Holds | Runs in | Section |
| :----------------------------- | :----------------------------------------------------------------- | :------------------------------------- | :-------------------------------------------- |
| `src/vitnode.config.ts` | Locales, metadata, logo, menus, theme, enabled plugins | Browser, server **and** your Vite build | [Shared config](#shared-config) |
| `src/vitnode.server.config.ts` | Message loaders | Server only | [Server config](#server-config) |
| `src/vitnode.server.config.ts` | Message loaders, SEO policy | Server only | [Server config](#server-config) |
| `src/start.ts` | The request middleware | Server | [Request pipeline](#request-pipeline) |
| `vite.config.ts` | The `vitnode()` Vite plugin and its options | Vite (dev and build) | [Vite config](#vite-config) |

Expand Down 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.ogImage` sets the default social image and `metadata.twitterSite` the X handle, see [Social images](/docs/dev/social-images) |
| `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/seo/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 Expand Up @@ -191,6 +191,7 @@ of those modules, and that is the part worth knowing:
| `src/blocks.gen.ts` | the plugin's `widgets` module | only by routes that render blocks |
| `src/package-messages.gen.ts` | the factory's `localeFiles` | per request, one locale at a time |
| `src/page-cache.gen.ts` | route `cache` options | by `src/server.ts`, to pick each page's HTML cache policy |
| `src/sitemap-sources.gen.ts` | content types' `delivery.sitemap` | by `src/server.ts`, to list their records in `/sitemap.xml` |
| `src/api-registry.gen.ts` | the plugin's `config.api` | never. Type-only, it teaches the fetcher which plugins exist |
| `src/plugin-inventory.gen.ts` | the factory's `metadata` | by the API only, through `buildApiConfig({ frontendPlugins })` |

Expand Down Expand Up @@ -261,6 +262,29 @@ export const loadIntlMessages = createIntlMessagesLoader(vitNodeServerConfig)
where you reword a string a package translates differently to how you want it.
[Languages & Localization](/docs/dev/i18n) covers both.

### Options

| Name | Type | Required | Default | Description |
| ----------------- | ----------------------------- | -------- | ------- | ------------------------------------------------------------------------------------------------- |
| `config` | `VitNodeConfig` | Yes | - | The shared config from `src/vitnode.config.ts`. |
| `messages` | `AppMessagesMap` | No | - | The app's own translations, merged over the packages' strings. |
| `packageMessages` | `Record<string, LocaleMessagesMap>` | No | - | The generated `src/package-messages.gen.ts`. |
| `seo` | `VitNodeSeoConfig` | No | `{ indexing: true }` | Search indexing, `/robots.txt`, `/sitemap.xml` and AI crawler rules, served by `withSeo`. |

`seo` is served by `withSeo` in `src/server.ts` and defaults `indexing` to `true`:

```ts title="apps/web/src/vitnode.server.config.ts"
export const vitNodeServerConfig = buildServerConfig({
config: vitNodeConfig,
messages: appMessages,
packageMessages,
seo: { sitemap: { paths: ['/', '/plugins'] } }, // [!code ++]
})
```

[Set up SEO](/docs/dev/seo/setup) turns it on, and the [SEO reference](/docs/dev/seo/reference)
lists every option.

<Callout type="info" title="The API has its own config">
`src/vitnode.api.config.ts` configures the Hono app at `/api/*` - the
database, storage, email, Redis. In a single app it reads `vitNodeConfig.i18n`
Expand Down
75 changes: 2 additions & 73 deletions apps/web/content/docs/dev/i18n/localized-urls-advanced.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Advanced localized URLs
description: Serve each language of a VitNode app from its own domain, see how a request's language is chosen, add hreflang and canonical links and fix URL errors.
description: Serve each language of a VitNode app from its own domain, see how a request's language is chosen, how Content Engine URLs follow along and fix URL errors.
icon: Globe2
---

Expand Down Expand Up @@ -113,78 +113,7 @@ Adding a translation doesn't break links people already shared. The old English

## hreflang and canonical links

A plugin page declares its alternates from `head()`, as **internal** paths, meaning the English route with each language's own values filled in. Only include translations that are actually published.

This example assumes an articles plugin whose `fetchArticle` helper returns one article:

```tsx title="plugins/articles/src/pages/article-page.tsx"
export const route = defineRoute({
load: async ({ params }) => await fetchArticle(params.slug),
head: ({ loaderData }) => ({
title: loaderData?.title,
// [!code ++:4]
alternates: {
en: '/articles/hello-world',
pl: '/articles/witaj-swiecie',
},
}),
})
```

VitNode turns that into a `canonical` link, one `alternate` per language and an `x-default` for the default locale, all absolute and spelled for each language: `https://vitnode.pl/artykuly/witaj-swiecie` with domains, or your `VITNODE_WEB_URL` plus `/pl/artykuly/witaj-swiecie` without them.

<Callout type="warn" title="Internal paths, not public ones">
Pass `/articles/witaj-swiecie`, not `/pl/artykuly/witaj-swiecie`. VitNode
always reads `alternates` as internal paths, so a public one would be
translated a second time. The delivery API gives you both. Each alternate has a public
`path` and an `internalPath`, and metadata has `canonicalInternalPath`.
</Callout>

A page backed by the Content System doesn't write any of this by hand. `@vitnode/core/tanstack/content` turns a delivery response into page data and a head. That covers redirects, 404s, the SEO title and description, and the internal alternates of every published translation. Blog's own post page is built this way (excerpt):

```tsx title="plugins/blog/src/pages/post-page.tsx"
import {
contentDeliveryPage,
contentDeliveryPageHead,
} from '@vitnode/core/tanstack/content'
import { defineRoute } from '@vitnode/core/tanstack/plugin-routes'

import { blogPostQueryOptions } from './post-query'

export const route = defineRoute({
load: async ({ context, params }) =>
contentDeliveryPage(
await context.queryClient.query(
blogPostQueryOptions({ locale: context.locale, slug: params.slug }),
),
),
head: ({ loaderData }) =>
contentDeliveryPageHead(loaderData?.metadata, {
title: loaderData?.item.title,
}),
})
```

`blogPostQueryOptions` calls the content type's public routes, `/delivery/resolve/{slug}` and `/{slug}` under `module: 'content/blog'`, and returns the resolution and the localized item that `contentDeliveryPage` expects.

A retired slug answers with a 308 to the current one, and an unknown slug is a 404.

App routes can do the same with `pageHead` or `localeAlternateLinks` from `@vitnode/core/tanstack/metadata`:

```tsx title="apps/web/src/routes/pricing.tsx"
import { localeAlternateLinks } from '@vitnode/core/tanstack/metadata'

export const Route = createFileRoute('/pricing')({
head: ({ match }) => ({
links: localeAlternateLinks({
internalPathname: '/pricing',
locale: match.context.locale,
}),
}),
})
```

`internalPathname` means "the same page in every locale". Pass `alternates: { en: '...', pl: '...' }` instead when the path differs per language.
A translated page declares its other languages with `alternates` in its `head`, as internal paths, and VitNode writes the canonical, `hreflang` and `x-default` links spelled with these rules. See [Canonical and hreflang](/docs/dev/seo/hreflang).

## Translated segments vs localized slugs

Expand Down
2 changes: 1 addition & 1 deletion apps/web/content/docs/dev/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"i18n",
"navigation",
"mobile-navigation",
"social-images",
"seo",
"performance",
"---Extend VitNode---",
"widgets",
Expand Down
6 changes: 3 additions & 3 deletions apps/web/content/docs/dev/routing/route-module.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ Throw `notFound()` or `redirect()` from `@tanstack/react-router` to answer with
| `title` | `string` | The page's own title, already translated. VitNode suffixes it with the site name from `buildConfig({ metadata })`. |
| `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). |
| `alternates` | `Record<string, string>` | Internal paths of the page in each language, for canonical and `hreflang` links. See [Advanced localized URLs](/docs/dev/seo/hreflang). |
| `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). |
| `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/seo/social-images). |

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`.
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/seo/social-images) when it sets no `openGraph.image`.

## Translated metadata

Expand Down
97 changes: 97 additions & 0 deletions apps/web/content/docs/dev/seo/ai-crawlers.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
---
title: AI crawlers
description: Allow or block OpenAI, Anthropic and Google AI crawlers separately for search and training with seo.crawlers in VitNode's generated robots.txt.
icon: Sparkles
---

`seo.crawlers` adds a `User-agent` group to the generated [robots.txt](/docs/dev/seo/robots-txt) for each AI crawler you name. Use it to stay in AI search results while opting out of training, or the other way round.

This guide assumes [SEO is set up](/docs/dev/seo/setup).

## Choose per bot

Each bot you leave out follows `User-agent: *`. Set a bot to `false` to give it its own `Disallow: /` group, or to `true` to give it an explicit allow group:

```ts title="src/vitnode.server.config.ts"
seo: {
indexing: true,
crawlers: {
openai: { search: true, training: false },
anthropic: { search: true, training: false },
googleExtended: false,
},
},
```

| Option | Bot | Used for |
| ----------------------------- | ------------------ | --------------------------------------------------------- |
| `crawlers.openai.search` | `OAI-SearchBot` | ChatGPT search results |
| `crawlers.openai.training` | `GPTBot` | OpenAI training data |
| `crawlers.anthropic.search` | `Claude-SearchBot` | Claude search results |
| `crawlers.anthropic.training` | `ClaudeBot` | Anthropic training data |
| `crawlers.googleExtended` | `Google-Extended` | Gemini training and grounding, as Google describes it |

## What robots.txt gets

The config above adds these groups after `User-agent: *`, shown for a site with English and Polish:

```txt
User-agent: OAI-SearchBot
Allow: /
Disallow: /admin
Disallow: /settings
Disallow: /pl/settings
Disallow: /modcp
Disallow: /pl/modcp
Disallow: /files
Disallow: /pl/files
Disallow: /login
Disallow: /pl/login
Disallow: /register
Disallow: /pl/register

User-agent: GPTBot
Disallow: /

User-agent: Claude-SearchBot
Allow: /
Disallow: /admin
Disallow: /settings
Disallow: /pl/settings
Disallow: /modcp
Disallow: /pl/modcp
Disallow: /files
Disallow: /pl/files
Disallow: /login
Disallow: /pl/login
Disallow: /register
Disallow: /pl/register

User-agent: ClaudeBot
Disallow: /

User-agent: Google-Extended
Disallow: /
```

An allowed bot gets the same `Disallow` lines as `User-agent: *` because a crawler obeys only the most specific group that names it. Without them, `Allow: /` alone would open the AdminCP to that bot.

## What these rules can't do

Crawler rules state a policy that well-behaved bots follow. They do not block HTTP requests, and they do not cover fetches a person starts, such as asking an assistant to open one page. `Google-Extended` never changes how Google Search crawls or ranks the site.

On Cloudflare, check that the zone's managed robots.txt does not add conflicting rules; see [robots.txt](/docs/dev/seo/robots-txt#check-the-result).

## Check the result

Restart the app and look for the group of one bot:

```bash
curl -s http://localhost:3000/robots.txt | grep -A1 'User-agent: GPTBot'
```

With `openai.training: false` it prints `User-agent: GPTBot` followed by `Disallow: /`.

## Related

- [SEO reference](/docs/dev/seo/reference#seo-options): every `seo` option and its default.
Loading
Loading