Skip to content

Commit c0a7413

Browse files
committed
chore: next14 native sitemap generator
1 parent b3ef95f commit c0a7413

File tree

5 files changed

+78
-178
lines changed

5 files changed

+78
-178
lines changed

next-sitemap.config.js

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

package-lock.json

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

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"dev": "next dev",
77
"prebuild": "node scripts/manage-faq-routes.js",
8-
"build": "next build && next-sitemap",
8+
"build": "next build",
99
"start": "npx serve@latest out",
1010
"lint": "next lint",
1111
"prepare": "husky install",
@@ -48,7 +48,6 @@
4848
"i18next": "^22.5.1",
4949
"lint-staged": "^13.2.1",
5050
"next-i18next": "^13.3.0",
51-
"next-sitemap": "^4.2.3",
5251
"postcss": "^8",
5352
"prettier": "^2.8.8",
5453
"react-i18next": "^12.3.1",

src/app/robots.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { MetadataRoute } from 'next';
2+
3+
export default function robots(): MetadataRoute.Robots {
4+
const baseUrl = process.env.NEXT_PUBLIC_HOME_URL || 'https://fastgpt.io';
5+
6+
return {
7+
rules: [
8+
{
9+
userAgent: '*',
10+
allow: '/',
11+
disallow: ['/api/', '/admin/']
12+
}
13+
],
14+
sitemap: `${baseUrl}/sitemap.xml`
15+
};
16+
}

src/app/sitemap.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { MetadataRoute } from 'next';
2+
3+
// Helper function to format date
4+
function formatDate(date: Date): string {
5+
return date.toISOString().replace(/\.\d{3}Z$/, 'Z');
6+
}
7+
8+
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
9+
const baseUrl = process.env.NEXT_PUBLIC_HOME_URL || 'https://fastgpt.io';
10+
const locales = ['en', 'zh', 'ja'];
11+
const now = formatDate(new Date());
12+
13+
const paths: MetadataRoute.Sitemap = [];
14+
15+
// Generate paths for different locales
16+
for (const locale of locales) {
17+
// Homepage with locale
18+
paths.push({
19+
url: `${baseUrl}/${locale}`,
20+
lastModified: now,
21+
changeFrequency: 'daily',
22+
priority: 1.0
23+
});
24+
25+
// Enterprise page
26+
paths.push({
27+
url: `${baseUrl}/${locale}/enterprise`,
28+
lastModified: now,
29+
changeFrequency: 'weekly',
30+
priority: 0.8
31+
});
32+
33+
// Price page
34+
paths.push({
35+
url: `${baseUrl}/${locale}/price`,
36+
lastModified: now,
37+
changeFrequency: 'weekly',
38+
priority: 0.8
39+
});
40+
41+
// FAQ page (only include if FAQ is enabled)
42+
if (process.env.NEXT_PUBLIC_FAQ === 'true') {
43+
paths.push({
44+
url: `${baseUrl}/${locale}/faq`,
45+
lastModified: now,
46+
changeFrequency: 'daily',
47+
priority: 0.9
48+
});
49+
}
50+
}
51+
52+
// Root homepage
53+
paths.push({
54+
url: baseUrl,
55+
lastModified: now,
56+
changeFrequency: 'daily',
57+
priority: 1.0
58+
});
59+
60+
return paths;
61+
}

0 commit comments

Comments
 (0)