Skip to content

Commit 3fc1285

Browse files
authored
docs: add OG images for website (#988)
1 parent baa60de commit 3fc1285

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

pnpm-lock.yaml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"react": "^19.1.0",
2323
"react-dom": "^19.1.0",
2424
"rsbuild-plugin-google-analytics": "1.0.3",
25+
"rsbuild-plugin-open-graph": "^1.0.2",
2526
"rspress": "2.0.0-beta.5",
2627
"rspress-plugin-font-open-sans": "1.0.0"
2728
}

website/rspress.config.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import { pluginLlms } from '@rspress/plugin-llms';
44
import { pluginRss } from '@rspress/plugin-rss';
55
import { transformerNotationHighlight } from '@shikijs/transformers';
66
import { pluginGoogleAnalytics } from 'rsbuild-plugin-google-analytics';
7+
import { pluginOpenGraph } from 'rsbuild-plugin-open-graph';
78
import { pluginFontOpenSans } from 'rspress-plugin-font-open-sans';
89
import { defineConfig } from 'rspress/config';
910

1011
const siteUrl = 'https://lib.rsbuild.dev';
12+
const description = 'The Rsbuild-based library development tool';
1113

1214
export default defineConfig({
1315
plugins: [
@@ -62,6 +64,17 @@ export default defineConfig({
6264
// exclude document fragments from routes
6365
exclude: ['**/zh/shared/**', '**/en/shared/**'],
6466
},
67+
head: [
68+
({ routePath }) => {
69+
const getOgImage = () => {
70+
if (routePath.endsWith('blog/introducing-rslib')) {
71+
return 'assets/rslib-og-image-introducing.png';
72+
}
73+
return 'rslib-og-image.png';
74+
};
75+
return `<meta property="og:image" content="https://assets.rspack.dev/rslib/${getOgImage()}">`;
76+
},
77+
],
6578
themeConfig: {
6679
socialLinks: [
6780
{
@@ -85,7 +98,7 @@ export default defineConfig({
8598
lang: 'en',
8699
label: 'English',
87100
title: 'Rslib',
88-
description: 'The Rsbuild-based library development tool',
101+
description,
89102
editLink: {
90103
docRepoBaseUrl:
91104
'https://github.com/web-infra-dev/rslib/tree/main/website/docs',
@@ -127,6 +140,19 @@ export default defineConfig({
127140
'@zh': path.join(__dirname, 'docs/zh'),
128141
},
129142
},
130-
plugins: [pluginGoogleAnalytics({ id: 'G-Q66CEHQ6JR' }), pluginSass()],
143+
plugins: [
144+
pluginGoogleAnalytics({ id: 'G-Q66CEHQ6JR' }),
145+
pluginSass(),
146+
pluginOpenGraph({
147+
title: 'Rslib',
148+
type: 'website',
149+
url: siteUrl,
150+
description,
151+
twitter: {
152+
site: '@rspack_dev',
153+
card: 'summary_large_image',
154+
},
155+
}),
156+
],
131157
},
132158
});

0 commit comments

Comments
 (0)