Skip to content

Commit 21133c6

Browse files
committed
feat: Replace NextSeo and DefaultSeo components with generateNextSeo and generateDefaultSeo functions for improved SEO tag generation in Next.js Pages Router. Update README and tests accordingly.
1 parent d483cfe commit 21133c6

File tree

9 files changed

+220
-191
lines changed

9 files changed

+220
-191
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "next-seo",
3-
"version": "7.0.0-alpha.2",
3+
"version": "7.0.0-alpha.9",
44
"description": "SEO plugin for Next.js projects",
55
"sideEffects": false,
66
"repository": {

src/pages/README.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Next SEO - Pages Router Support
22

3-
This directory contains SEO components for Next.js Pages Router applications.
3+
This directory contains SEO generation functions for Next.js Pages Router applications.
44

5-
> **Note:** These components are specifically for Pages Router. For App Router applications, use the main next-seo package exports instead.
5+
> **Note:** These functions are specifically for Pages Router. For App Router applications, use the main next-seo package exports instead.
66
77
## Installation
88

@@ -19,29 +19,29 @@ pnpm add next-seo
1919
Import from `next-seo/pages` instead of `next-seo`:
2020

2121
```tsx
22-
import { NextSeo, DefaultSeo } from "next-seo/pages";
22+
import { generateNextSeo, generateDefaultSeo } from "next-seo/pages";
2323
```
2424

25-
> **Important:** In Pages Router, you need to wrap the SEO components with Next.js's `<Head>` component to ensure the meta tags are properly rendered in the document head.
25+
> **Important:** In Pages Router, you need to wrap the generated SEO tags with Next.js's `<Head>` component to ensure the meta tags are properly rendered in the document head.
2626
27-
### NextSeo Component
27+
### generateNextSeo Function
2828

2929
Add SEO meta tags to individual pages:
3030

3131
```tsx
3232
// pages/about.tsx
3333
import Head from "next/head";
34-
import { NextSeo } from "next-seo/pages";
34+
import { generateNextSeo } from "next-seo/pages";
3535

3636
export default function AboutPage() {
3737
return (
3838
<>
3939
<Head>
40-
<NextSeo
41-
title="About Us"
42-
description="Learn more about our company"
43-
canonical="https://example.com/about"
44-
openGraph={{
40+
{generateNextSeo({
41+
title: "About Us",
42+
description: "Learn more about our company",
43+
canonical: "https://example.com/about",
44+
openGraph: {
4545
url: "https://example.com/about",
4646
title: "About Us",
4747
description: "Learn more about our company",
@@ -53,8 +53,8 @@ export default function AboutPage() {
5353
alt: "About Us",
5454
},
5555
],
56-
}}
57-
/>
56+
},
57+
})}
5858
</Head>
5959
<h1>About Us</h1>
6060
{/* Page content */}
@@ -63,15 +63,15 @@ export default function AboutPage() {
6363
}
6464
```
6565

66-
### DefaultSeo Component
66+
### generateDefaultSeo Function
6767

6868
Set global SEO defaults in your `_app.tsx`:
6969

7070
```tsx
7171
// pages/_app.tsx
7272
import type { AppProps } from "next/app";
7373
import Head from "next/head";
74-
import { DefaultSeo } from "next-seo/pages";
74+
import { generateDefaultSeo } from "next-seo/pages";
7575

7676
const DEFAULT_SEO = {
7777
titleTemplate: "MySite | %s",
@@ -93,9 +93,7 @@ const DEFAULT_SEO = {
9393
export default function MyApp({ Component, pageProps }: AppProps) {
9494
return (
9595
<>
96-
<Head>
97-
<DefaultSeo {...DEFAULT_SEO} />
98-
</Head>
96+
<Head>{generateDefaultSeo(DEFAULT_SEO)}</Head>
9997
<Component {...pageProps} />
10098
</>
10199
);
@@ -178,14 +176,16 @@ additionalLinkTags={[
178176

179177
## Migration from Legacy Import
180178

181-
If you're using the old import path, update your imports:
179+
If you're using the old import path or component-based approach, update your code:
182180

183181
```tsx
184-
// Old (deprecated)
182+
// Old (deprecated components)
185183
import { NextSeo, DefaultSeo } from "next-seo";
184+
// Usage: <NextSeo title="..." />
186185
187-
// New (Pages Router)
188-
import { NextSeo, DefaultSeo } from "next-seo/pages";
186+
// New (Pages Router functions)
187+
import { generateNextSeo, generateDefaultSeo } from "next-seo/pages";
188+
// Usage: {generateNextSeo({ title: "..." })}
189189
```
190190

191191
## TypeScript Support

src/pages/components/DefaultSeo.tsx

Lines changed: 0 additions & 86 deletions
This file was deleted.

src/pages/components/NextSeo.tsx

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/pages/components/WithHead.tsx

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/pages/core/__snapshots__/buildTags.test.tsx.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`buildTags > Article SEO renders correctly 1`] = `
3+
exports[`buildTags and generateSeoTags > Article SEO renders correctly 1`] = `
44
[
55
<title>
66
Next SEO | Article Page Title
@@ -112,7 +112,7 @@ exports[`buildTags > Article SEO renders correctly 1`] = `
112112
]
113113
`;
114114

115-
exports[`buildTags > Book SEO renders correctly 1`] = `
115+
exports[`buildTags and generateSeoTags > Book SEO renders correctly 1`] = `
116116
[
117117
<title>
118118
Next SEO | Book Page Title
@@ -216,7 +216,7 @@ exports[`buildTags > Book SEO renders correctly 1`] = `
216216
]
217217
`;
218218

219-
exports[`buildTags > Profile SEO renders correctly 1`] = `
219+
exports[`buildTags and generateSeoTags > Profile SEO renders correctly 1`] = `
220220
[
221221
<title>
222222
Next SEO | Profile Page Title
@@ -312,7 +312,7 @@ exports[`buildTags > Profile SEO renders correctly 1`] = `
312312
]
313313
`;
314314

315-
exports[`buildTags > Video SEO renders correctly 1`] = `
315+
exports[`buildTags and generateSeoTags > Video SEO renders correctly 1`] = `
316316
[
317317
<title>
318318
Next SEO | Video Page Title
@@ -440,7 +440,7 @@ exports[`buildTags > Video SEO renders correctly 1`] = `
440440
]
441441
`;
442442

443-
exports[`buildTags > renders correctly 1`] = `
443+
exports[`buildTags and generateSeoTags > renders correctly 1`] = `
444444
[
445445
<title>
446446
This is a test title.

0 commit comments

Comments
 (0)