Skip to content

Commit 8df934e

Browse files
sunya9claude
andauthored
feat: Vite 8 support and OG meta tag enhancements (#154)
* chore: update deps * chore(deps): update font source and Vite version in configuration * refactor: streamline image generation logic and improve module loading * fix: update schema path in biome configuration * feat: enhance Open Graph meta tags with width, height, type, and alt attributes * fix: sync lockfile with package.json and correct font name in example - Regenerate pnpm-lock.yaml to resolve vite version mismatch (^7.1.2 vs ^8.0.3) causing CI --frozen-lockfile failure - Fix font name in og-image.tsx from "Noto Serif JP" to "Noto Sans" to match vite.config.ts registration Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: correct font name to "Noto Sans JP" to match @fontsource/noto-sans-jp Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0136d5b commit 8df934e

12 files changed

Lines changed: 516 additions & 304 deletions

README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,15 @@ export default function OgImage() {
7474

7575
### 3. Complete!
7676

77-
The plugin automatically inserts the necessary `og:image` meta tag in your HTML. You can add other Open Graph meta tags as needed:
77+
The plugin automatically inserts the following meta tags in your HTML:
78+
79+
- `og:image` — Image URL
80+
- `og:image:type` — Always `image/png`
81+
- `og:image:width` — Image width (default: 1200)
82+
- `og:image:height` — Image height (default: 630)
83+
- `og:image:alt` — Alt text (when `alt` option is set)
84+
85+
You can add other Open Graph meta tags as needed:
7886

7987
```html
8088
<!-- index.html - Add these manually if needed -->
@@ -119,6 +127,12 @@ interface OgImagePluginOptions {
119127
*/
120128
componentPath?: string;
121129

130+
/**
131+
* Alt text for the OG image
132+
* When set, generates an og:image:alt meta tag
133+
*/
134+
alt?: string;
135+
122136
/**
123137
* Image response options (from @vercel/og)
124138
* See: https://vercel.com/docs/functions/og-image-generation
@@ -147,7 +161,7 @@ interface OgImagePluginOptions {
147161
Use [@fontsource](https://fontsource.org/) packages for easy font integration:
148162

149163
```bash
150-
pnpm add @fontsource/geist @fontsource/noto-serif-jp
164+
pnpm add @fontsource/geist @fontsource/noto-sans-jp
151165
```
152166

153167
```typescript
@@ -158,6 +172,7 @@ export default defineConfig({
158172
react(),
159173
reactOgImage({
160174
host: "https://example.com",
175+
alt: "Your Amazing App",
161176
imageResponseOptions: {
162177
fonts: [
163178
{
@@ -168,9 +183,9 @@ export default defineConfig({
168183
weight: 700,
169184
},
170185
{
171-
name: "Noto Serif JP",
186+
name: "Noto Sans JP",
172187
data: await readFile(
173-
"./node_modules/@fontsource/noto-serif-jp/files/noto-serif-jp-japanese-400-normal.woff"
188+
"./node_modules/@fontsource/noto-sans-jp/files/noto-sans-jp-japanese-400-normal.woff"
174189
),
175190
weight: 400,
176191
},

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/2.1.4/schema.json",
2+
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
33
"vcs": {
44
"enabled": false,
55
"clientKind": "git",

example/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"devDependencies": {
1818
"@eslint/js": "^10.0.1",
1919
"@fontsource/geist": "^5.2.6",
20-
"@fontsource/noto-serif-jp": "^5.2.6",
20+
"@fontsource/noto-sans-jp": "^5.2.9",
2121
"@types/react": "^19.1.10",
2222
"@types/react-dom": "^19.1.7",
2323
"@vitejs/plugin-react": "^5.0.0",
@@ -28,7 +28,7 @@
2828
"globals": "^17.3.0",
2929
"typescript": "^5.9.2",
3030
"typescript-eslint": "^8.39.1",
31-
"vite": "^7.1.2",
31+
"vite": "^8.0.3",
3232
"vite-plugin-react-og-image": "link:..",
3333
"vitest": "^4.0.3"
3434
}

example/src/og-image.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default function OgImage() {
2727
fontSize: 36,
2828
opacity: 0.8,
2929
fontWeight: 400,
30-
fontFamily: "Noto Serif JP",
30+
fontFamily: "Noto Sans JP",
3131
}}
3232
>
3333
日本語のサンプルテキストです

example/test/build.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,17 @@ test("should update index.html with correct asset path", async () => {
5454
expect(ogImageMeta.attr("content")).toMatch(
5555
/^https:\/\/example\.com\/assets\/og-image-\w+\.png$/
5656
);
57+
58+
// Check og:image:width and og:image:height meta tags
59+
const ogImageWidth = $('meta[property="og:image:width"]');
60+
const ogImageHeight = $('meta[property="og:image:height"]');
61+
expect(ogImageWidth.attr("content")).toBe("1200");
62+
expect(ogImageHeight.attr("content")).toBe("630");
63+
64+
// Check og:image:type and og:image:alt meta tags
65+
const ogImageType = $('meta[property="og:image:type"]');
66+
expect(ogImageType.attr("content")).toBe("image/png");
67+
68+
const ogImageAlt = $('meta[property="og:image:alt"]');
69+
expect(ogImageAlt.attr("content")).toBe("Vite React OG Image Example");
5770
});

example/test/dev-server.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,17 @@ test("should serve HTML with og:image meta tag pointing to preview", async () =>
4747
// Check og:image meta tag
4848
const ogImageMeta = $('meta[property="og:image"]');
4949
expect(ogImageMeta.attr("content")).toBe(`${ogImageHost}/src/og-image.tsx`);
50+
51+
// Check og:image:width and og:image:height meta tags
52+
const ogImageWidth = $('meta[property="og:image:width"]');
53+
const ogImageHeight = $('meta[property="og:image:height"]');
54+
expect(ogImageWidth.attr("content")).toBe("1200");
55+
expect(ogImageHeight.attr("content")).toBe("630");
56+
57+
// Check og:image:type and og:image:alt meta tags
58+
const ogImageType = $('meta[property="og:image:type"]');
59+
expect(ogImageType.attr("content")).toBe("image/png");
60+
61+
const ogImageAlt = $('meta[property="og:image:alt"]');
62+
expect(ogImageAlt.attr("content")).toBe("Vite React OG Image Example");
5063
});

example/vite.config.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,22 @@ export default defineConfig(async () => {
1111
react(),
1212
reactOgImage({
1313
host: "https://example.com",
14+
alt: "Vite React OG Image Example",
1415
imageResponseOptions: {
1516
fonts: [
1617
{
1718
name: "Geist",
1819
data: await readFile(
19-
"./node_modules/@fontsource/geist/files/geist-latin-700-normal.woff"
20+
"./node_modules/@fontsource/geist/files/geist-latin-700-normal.woff",
2021
),
22+
weight: 700,
2123
},
2224
{
23-
name: "Noto Sans",
25+
name: "Noto Sans JP",
2426
data: await readFile(
25-
"./node_modules/@fontsource/noto-serif-jp/files/noto-serif-jp-japanese-400-normal.woff"
27+
"./node_modules/@fontsource/noto-sans-jp/files/noto-sans-jp-japanese-400-normal.woff",
2628
),
29+
weight: 400,
2730
},
2831
],
2932
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"@types/react": "^19.1.8",
5050
"tsup": "^8.5.0",
5151
"typescript": "^5.9.2",
52-
"vite": "^7.1.2"
52+
"vite": "^8.0.3"
5353
},
5454
"peerDependencies": {
5555
"react": ">=18.0.0",

0 commit comments

Comments
 (0)