Skip to content

Commit 1d1f62e

Browse files
committed
feat(marketing): ✨ Enhance marketing page loading and metadata handling
- Introduced `loadMarketingPageText` function to fetch localized marketing page text for home, plugins, and solutions routes. - Updated route loaders to utilize the new function, improving text retrieval and head metadata generation. - Enhanced Open Graph metadata handling for better social sharing, including support for localized titles and descriptions. - Added support for category labels and icons in generated Open Graph images. - Improved overall structure and readability of metadata handling in the API.
1 parent e13fd08 commit 1d1f62e

26 files changed

Lines changed: 882 additions & 92 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ The page's `head` calls `contentDeliveryPageHead` with the resolve route's answe
118118
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.
119119

120120
- **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.
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 (the record's title when the file has none). A record without a cover then falls back to the site card, drawn with its title and description. The blog plugin works this way.
122122

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

‎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}`. `metadata.ogImage` sets the default social image, see [Social images](/docs/dev/social-images) |
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/social-images.mdx‎

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ icon: Image
77
import { ImgDocs } from "@/components/fumadocs/img";
88
import cardExample from "./social-images-card.webp";
99

10-
When someone shares a VitNode link on Facebook, LinkedIn, X, Slack or Discord, the preview shows the page's `og:image`. VitNode fills it for you: the API draws a social card, and every page head points at it. The card is a pull quote headed by the site's logo: the page's description as a large quote, signed with its title, and the page's cover, when it has one, on the right side, fading smoothly into the background beside the quote. No headless browser runs, and nothing is fetched from the internet: the fonts ship with VitNode and covers come from your own storage.
10+
When someone shares a VitNode link on Facebook, LinkedIn, X, Slack or Discord, the preview shows the page's `og:image`. VitNode fills it for you: the API draws a social card, and every page head points at it. The card is headed by the site's logo, with the page's title as the headline, its description underneath, and the page's cover, when it has one, on the right side, fading smoothly into the background beside the text. No headless browser runs, and nothing is fetched from the internet: the fonts ship with VitNode and covers come from your own storage.
1111

1212
<ImgDocs
1313
src={cardExample}
@@ -19,10 +19,67 @@ When someone shares a VitNode link on Facebook, LinkedIn, X, Slack or Discord, t
1919
| Page | `og:image` |
2020
| ------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------ |
2121
| A Content Engine record whose type sets `delivery.seo.openGraph` | Its card at `/api/{plugin}/content/{path}/delivery/og/{slug}`, with the [`imageField`](/docs/content-engine/seo#social-images) cover in the background |
22-
| A member profile (`/users/{nameCode}`) | The member's card at `/api/@vitnode/core/og/users/{nameCode}`: headline as the quote, name and avatar, profile cover in the background |
23-
| Any other page with a title | The site card at `/api/@vitnode/core/og/site` |
22+
| A member profile (`/users/{nameCode}`) | The member's card at `/api/@vitnode/core/og/users/{nameCode}`: name, profile headline and avatar, profile cover in the background |
23+
| Any other page with a title | The site card at `/api/@vitnode/core/og/site`, drawn with the page's own `title` and `description` from the URL |
24+
25+
Give the site card a coloured label and an icon with `openGraph`:
26+
27+
```ts title="apps/web/src/routes/_docs/docs.$.tsx"
28+
head: ({ loaderData }) =>
29+
pageHead({
30+
title: loaderData?.metaTitle,
31+
description: loaderData?.description,
32+
// [!code ++:4]
33+
openGraph: {
34+
imageCategory: { title: "Content Engine", color: "#61bd67" },
35+
imageIcon: "M12 2v10M18.4 6.6a9 9 0 1 1-12.77.04",
36+
},
37+
}),
38+
```
39+
40+
- `imageCategory` puts a label above the title, and its `color` (`#rrggbb`) tints the label, the icon and the bar at the bottom. VitNode's docs use it for the section a page lives in.
41+
- `imageIcon` frames an icon in the top-right corner: SVG path data on Lucide's 24 × 24 grid, drawn as a stroke. Anything but plain path data is dropped, so the card never draws markup from the URL.
42+
- `imageLayout: "quote"` swaps the headline for a pull quote: the description large, signed with the title.
43+
44+
A page with a title also gets `og:title`, `og:description`, `og:type`, `og:site_name`, `og:url` (its canonical URL), `og:locale` (as `en_US`, even when the locale is just `en`), one `og:locale:alternate` per other language it has `alternates` in, and the X card tags `twitter:card`, `twitter:title`, `twitter:description`, `twitter:image` and `twitter:image:alt`. A layout that only sets `robots` gets none of them.
2445

25-
A page with a title also gets `og:title`, `og:description`, `og:type`, `og:site_name`, `og:url` (its canonical URL), `og:locale` and `twitter:card`. A layout that only sets `robots` gets none of them.
46+
Set `metadata.twitterSite` to your X handle and every page also gets `twitter:site`:
47+
48+
```ts title="apps/web/src/vitnode.config.ts"
49+
export const vitNodeConfig = buildConfig({
50+
metadata: {
51+
title: "Acme Community",
52+
// [!code ++]
53+
twitterSite: "@acme",
54+
},
55+
// ...
56+
});
57+
```
58+
59+
Pages that pass no canonical URL or locale still get `og:url` and `og:locale` from the root route. Add `documentSocialMeta` to its `head`, and give it the public pathname from `beforeLoad`:
60+
61+
```tsx title="apps/web/src/routes/__root.tsx"
62+
// [!code ++]
63+
import { documentSocialMeta } from "@vitnode/core/tanstack/metadata";
64+
65+
export const Route = createRootRouteWithContext<RootRouterContext>()({
66+
beforeLoad: ({ location }) => {
67+
const publicPathname = publicPathnameOf(location);
68+
69+
// [!code ++]
70+
return { locale: resolveLocale<Locale>(publicPathname), publicPathname };
71+
},
72+
head: ({ match }) => ({
73+
meta: [
74+
// [!code ++:4]
75+
...documentSocialMeta({
76+
locale: match.context.locale,
77+
pathname: match.context.publicPathname,
78+
}),
79+
],
80+
}),
81+
});
82+
```
2683

2784
Each card URL carries a `v` version made from what the card shows. While `v` matches, the API answers with `Cache-Control: public, max-age=31536000, immutable`, so a CDN can keep the image for a year. Edit the title and the page links a new URL. An outdated `v` still gets the current card, cached for an hour.
2885

‎apps/web/src/docs/icons.server.ts‎

Lines changed: 121 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import '@tanstack/react-start/server-only'
22

3-
import type { Root } from 'fumadocs-core/page-tree'
3+
import type { Node, Root } from 'fumadocs-core/page-tree'
44

55
import { visit } from 'fumadocs-core/page-tree'
66
import dynamicIconImports from 'lucide-react/dynamicIconImports.mjs'
@@ -57,3 +57,123 @@ export const loadDocsPageTreeIcons = async (
5757

5858
return Object.fromEntries(entries.flat())
5959
}
60+
61+
const numbers = (attributes: Record<string, string>, ...names: string[]) =>
62+
names.map((name) => Number(attributes[name] ?? 0))
63+
64+
const pointsPath = (points: string | undefined, closed: boolean) => {
65+
const coordinates = (points ?? '').trim()
66+
67+
return coordinates ? `M${coordinates}${closed ? 'Z' : ''}` : ''
68+
}
69+
70+
const ellipsePath = (cx: number, cy: number, rx: number, ry: number) =>
71+
`M${cx - rx} ${cy}a${rx} ${ry} 0 1 0 ${rx * 2} 0a${rx} ${ry} 0 1 0 ${-rx * 2} 0`
72+
73+
const rectPath = (attributes: Record<string, string>) => {
74+
const [x, y, width, height] = numbers(attributes, 'x', 'y', 'width', 'height')
75+
const rx = Math.min(Number(attributes.rx ?? attributes.ry ?? 0), width / 2)
76+
const ry = Math.min(Number(attributes.ry ?? attributes.rx ?? 0), height / 2)
77+
78+
if (rx === 0 && ry === 0) return `M${x} ${y}h${width}v${height}h${-width}Z`
79+
80+
return [
81+
`M${x + rx} ${y}`,
82+
`H${x + width - rx}`,
83+
`A${rx} ${ry} 0 0 1 ${x + width} ${y + ry}`,
84+
`V${y + height - ry}`,
85+
`A${rx} ${ry} 0 0 1 ${x + width - rx} ${y + height}`,
86+
`H${x + rx}`,
87+
`A${rx} ${ry} 0 0 1 ${x} ${y + height - ry}`,
88+
`V${y + ry}`,
89+
`A${rx} ${ry} 0 0 1 ${x + rx} ${y}`,
90+
'Z',
91+
].join('')
92+
}
93+
94+
const NUMBER = String.raw`-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?`
95+
const LEADING_RELATIVE_MOVE = new RegExp(
96+
String.raw`^\s*m\s*(${NUMBER})[\s,]*(${NUMBER})[\s,]*`,
97+
'i',
98+
)
99+
100+
const standalonePath = (d: string) => {
101+
const match = LEADING_RELATIVE_MOVE.exec(d)
102+
if (!match || d.trimStart().startsWith('M')) return d
103+
104+
const rest = d.slice(match[0].length)
105+
const implicitLines = rest !== '' && !/^[a-z]/i.test(rest)
106+
107+
return `M${match[1]} ${match[2]}${implicitLines ? 'l' : ''}${rest}`
108+
}
109+
110+
const shapePath = ([tag, attributes]: DocsIconNode[number]) => {
111+
switch (tag) {
112+
case 'circle': {
113+
const [cx, cy, r] = numbers(attributes, 'cx', 'cy', 'r')
114+
115+
return ellipsePath(cx, cy, r, r)
116+
}
117+
case 'ellipse': {
118+
const [cx, cy, rx, ry] = numbers(attributes, 'cx', 'cy', 'rx', 'ry')
119+
120+
return ellipsePath(cx, cy, rx, ry)
121+
}
122+
case 'line': {
123+
const [x1, y1, x2, y2] = numbers(attributes, 'x1', 'y1', 'x2', 'y2')
124+
125+
return `M${x1} ${y1}L${x2} ${y2}`
126+
}
127+
case 'path':
128+
return standalonePath(attributes.d ?? '')
129+
case 'polygon':
130+
return pointsPath(attributes.points, true)
131+
case 'polyline':
132+
return pointsPath(attributes.points, false)
133+
case 'rect':
134+
return rectPath(attributes)
135+
default:
136+
return ''
137+
}
138+
}
139+
140+
export const loadDocsIconPathData = async (
141+
name: string | undefined,
142+
): Promise<string | undefined> => {
143+
const load = name ? iconImports.get(name) : undefined
144+
if (!load) return undefined
145+
146+
const node = toDocsIconNode((await load()).__iconData.node)
147+
148+
return node.map(shapePath).filter(Boolean).join('') || undefined
149+
}
150+
151+
const treePathOf = (nodes: readonly Node[], url: string): Node[] | null => {
152+
for (const node of nodes) {
153+
if (node.type === 'page' && node.url === url) return [node]
154+
if (node.type !== 'folder') continue
155+
if (node.index?.url === url) return [node, node.index]
156+
157+
const path = treePathOf(node.children, url)
158+
if (path) return [node, ...path]
159+
}
160+
161+
return null
162+
}
163+
164+
const iconNameOf = (node: Node) =>
165+
'icon' in node && typeof node.icon === 'string' ? node.icon : undefined
166+
167+
export const docsPagePlacement = (tree: Root, url: string) => {
168+
const path = treePathOf(tree.children, url) ?? []
169+
const [top] = path
170+
const sectionTitle =
171+
top?.type === 'folder' && top.root && typeof top.name === 'string'
172+
? top.name
173+
: undefined
174+
175+
return {
176+
iconName: path.map(iconNameOf).filter(Boolean).at(-1),
177+
sectionTitle,
178+
}
179+
}

‎apps/web/src/docs/section.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,18 @@ export const docsSectionOf = (pathname: string): string | undefined => {
33

44
return docs === 'docs' && section ? section : undefined
55
}
6+
7+
const DOCS_SECTION_OG_COLORS: Readonly<Record<string, string>> = {
8+
brand: '#f2798f',
9+
'content-engine': '#61bd67',
10+
dev: '#ff8a3f',
11+
guides: '#5c8af0',
12+
ui: '#04b991',
13+
}
14+
15+
export const docsSectionOgCategory = (
16+
section: null | undefined | { id: string; title: string },
17+
) =>
18+
section
19+
? { color: DOCS_SECTION_OG_COLORS[section.id], title: section.title }
20+
: undefined

‎apps/web/src/docs/transport.ts‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import { createServerFn } from '@tanstack/react-start'
33
import { getBreadcrumbItems } from 'fumadocs-core/breadcrumb'
44
import { z } from 'zod'
55

6-
import { loadDocsPageTreeIcons } from './icons.server'
6+
import {
7+
docsPagePlacement,
8+
loadDocsIconPathData,
9+
loadDocsPageTreeIcons,
10+
} from './icons.server'
711
import { docsGithubUrl, encodeMarkdownUrl } from './shared'
812
import { source } from './source.server'
913

@@ -14,23 +18,31 @@ const docsSlugSchema = z
1418

1519
export const getDocsPage = createServerFn({ method: 'GET' })
1620
.validator(docsSlugSchema)
17-
.handler(({ data: slugs }) => {
21+
.handler(async ({ data: slugs }) => {
1822
const page = source.getPage(slugs)
1923

2024
// oxlint-disable-next-line typescript/only-throw-error
2125
if (!page) throw notFound()
2226

23-
const ancestors = getBreadcrumbItems(page.url, source.getPageTree(), {})
27+
const tree = source.getPageTree()
28+
const ancestors = getBreadcrumbItems(page.url, tree, {})
2429
.slice(0, -1)
2530
.reverse()
2631
.flatMap((item) => (typeof item.name === 'string' ? [item.name] : []))
32+
const section = page.slugs[0]
33+
const { iconName, sectionTitle } = docsPagePlacement(tree, page.url)
34+
35+
const icon = await loadDocsIconPathData(iconName)
2736

2837
return {
2938
description: page.data.description,
3039
githubUrl: docsGithubUrl(page.path),
3140
markdownUrl: encodeMarkdownUrl(page.slugs),
3241
metaTitle: [page.data.title, ...ancestors].join(' - '),
3342
path: page.path,
43+
ogIcon: icon ?? null,
44+
section:
45+
section && sectionTitle ? { id: section, title: sectionTitle } : null,
3446
url: page.url,
3547
}
3648
})

‎apps/web/src/locales/site/en.json‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,20 @@
358358
"browse": "Browse",
359359
"browse_description": "A paginated list, shipped by the newsroom plugin.",
360360
"search": "Search"
361+
},
362+
"meta": {
363+
"home": {
364+
"title": "Open-Source Community Framework",
365+
"description": "VitNode is a free, open-source community framework with plugins, a Content Engine, AdminCP, real-time updates, AI building blocks and search."
366+
},
367+
"plugins": {
368+
"title": "Plugins - The Blog, the Example and Features of Your Own",
369+
"description": "Every VitNode feature ships as a plugin. Meet the blog plugin, the example plugin for learning, and see what a plugin of your own looks like."
370+
},
371+
"solutions": {
372+
"title": "Solutions - Five Sites Built with VitNode",
373+
"description": "Five sites built with VitNode: a help center, a membership site, an open-source hub, a gaming guild hub and a multilingual magazine, with roles and screens."
374+
}
361375
}
362376
}
363377
}

‎apps/web/src/locales/site/pl.json‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,20 @@
358358
"browse": "Przeglądaj",
359359
"browse_description": "Lista ze stronicowaniem z wtyczki newsroom.",
360360
"search": "Szukaj"
361+
},
362+
"meta": {
363+
"home": {
364+
"title": "Open-source framework dla społeczności",
365+
"description": "VitNode to darmowy, open-source framework dla społeczności z wtyczkami, Content Engine, AdminCP, aktualizacjami na żywo, klockami AI i wyszukiwarką."
366+
},
367+
"plugins": {
368+
"title": "Wtyczki - blog, przykład i funkcje Twojego autorstwa",
369+
"description": "Każda funkcja VitNode to wtyczka. Poznaj wtyczkę bloga, przykładową wtyczkę do nauki i zobacz, jak wygląda Twoja własna wtyczka."
370+
},
371+
"solutions": {
372+
"title": "Rozwiązania - pięć stron zbudowanych na VitNode",
373+
"description": "Pięć stron zbudowanych na VitNode: centrum pomocy, serwis z członkostwem, hub open source, hub gildii graczy i wielojęzyczny magazyn, z rolami i ekranami."
374+
}
361375
}
362376
}
363377
}

‎apps/web/src/routes/__root.tsx‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
DocumentScripts,
1414
VitNodeRootProviders,
1515
} from '@vitnode/core/tanstack/layout'
16+
import { documentSocialMeta } from '@vitnode/core/tanstack/metadata'
1617

1718
import type { Locale } from '@/vitnode.config'
1819

@@ -29,17 +30,22 @@ export interface RootRouterContext {
2930
}
3031

3132
export const Route = createRootRouteWithContext<RootRouterContext>()({
32-
beforeLoad: ({ location }) => ({
33-
locale: resolveLocale<Locale>(publicPathnameOf(location)),
34-
}),
33+
beforeLoad: ({ location }) => {
34+
const publicPathname = publicPathnameOf(location)
35+
36+
return {
37+
locale: resolveLocale<Locale>(publicPathname),
38+
publicPathname,
39+
}
40+
},
3541
component: RootComponent,
3642
loader: async ({ context }) => {
3743
await context.queryClient.query({
3844
...intlQueryOptions({ locale: context.locale }),
3945
staleTime: 'static',
4046
})
4147
},
42-
head: ({ matches }) => ({
48+
head: ({ match, matches }) => ({
4349
links: [
4450
...(matches.some(({ routeId }) => isDocsRouteId(routeId))
4551
? []
@@ -59,6 +65,10 @@ export const Route = createRootRouteWithContext<RootRouterContext>()({
5965
name: 'viewport',
6066
},
6167
{ title: metadata.title },
68+
...documentSocialMeta({
69+
locale: match.context.locale,
70+
pathname: match.context.publicPathname,
71+
}),
6272
],
6373
}),
6474
shellComponent: RootDocument,

0 commit comments

Comments
 (0)