Skip to content

Commit 53a8bab

Browse files
FinleyGeclaudehappy-otter
authored
feat: enhance sitemap support with multilingual and dynamic FAQ routing (#118)
- Add comprehensive sitemap configuration supporting all locales (en, zh, ja) - Include dynamic FAQ detail pages based on NEXT_PUBLIC_FAQ environment variable - Set appropriate priorities and changefreq for different page types - Add proper robots.txt configuration with sitemap reference - Support both homepage and language-specific pages - Include enterprise, pricing, and FAQ pages with SEO optimization Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-authored-by: Claude <[email protected]> Co-authored-by: Happy <[email protected]>
1 parent 6c931bd commit 53a8bab

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

next-sitemap.config.js

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,127 @@ module.exports = {
44
siteUrl: process.env.NEXT_PUBLIC_HOME_URL || "https://fastgpt.io",
55
generateRobotsTxt: true,
66
sitemapSize: 7000,
7+
8+
// Additional paths to include in the sitemap
9+
additionalPaths: async (config) => {
10+
const locales = ['en', 'zh', 'ja'];
11+
const paths = [];
12+
13+
// Only include FAQ paths if FAQ feature is enabled
14+
const faqEnabled = process.env.NEXT_PUBLIC_FAQ === 'true';
15+
16+
// Generate paths for different locales
17+
for (const locale of locales) {
18+
// Homepage with locale
19+
paths.push({
20+
loc: `/${locale}`,
21+
lastMod: new Date().toISOString(),
22+
changefreq: 'daily',
23+
priority: 1.0
24+
});
25+
26+
// Enterprise page
27+
paths.push({
28+
loc: `/${locale}/enterprise`,
29+
lastMod: new Date().toISOString(),
30+
changefreq: 'weekly',
31+
priority: 0.8
32+
});
33+
34+
// Price page
35+
paths.push({
36+
loc: `/${locale}/price`,
37+
lastMod: new Date().toISOString(),
38+
changefreq: 'weekly',
39+
priority: 0.8
40+
});
41+
42+
// FAQ page
43+
paths.push({
44+
loc: `/${locale}/faq`,
45+
lastMod: new Date().toISOString(),
46+
changefreq: 'daily',
47+
priority: 0.9
48+
});
49+
50+
// FAQ detail pages (only if FAQ is enabled)
51+
if (faqEnabled) {
52+
try {
53+
// Import FAQ data dynamically - handle both .ts and .js extensions
54+
const faqModule = await import('./src/faq.ts').catch(() => import('./src/faq.js'));
55+
const { faq } = faqModule;
56+
const faqIds = Object.keys(faq);
57+
58+
// Add each FAQ detail page
59+
faqIds.forEach((id) => {
60+
paths.push({
61+
loc: `/${locale}/faq/${id}`,
62+
lastMod: new Date().toISOString(),
63+
changefreq: 'weekly',
64+
priority: 0.7
65+
});
66+
});
67+
} catch (error) {
68+
console.warn('Could not load FAQ data for sitemap generation:', error.message);
69+
// If FAQ data loading fails, at least add the FAQ list page
70+
}
71+
}
72+
}
73+
74+
// Root homepage
75+
paths.push({
76+
loc: '/',
77+
lastMod: new Date().toISOString(),
78+
changefreq: 'daily',
79+
priority: 1.0
80+
});
81+
82+
return paths;
83+
},
84+
85+
// Custom transformation for URLs
86+
transform: async (config, path) => {
87+
// Add priority based on path type
88+
if (path.includes('/faq')) {
89+
return {
90+
...path,
91+
priority: 0.9,
92+
changefreq: 'daily'
93+
};
94+
}
95+
96+
if (path.includes('/enterprise') || path.includes('/price')) {
97+
return {
98+
...path,
99+
priority: 0.8,
100+
changefreq: 'weekly'
101+
};
102+
}
103+
104+
return {
105+
...path,
106+
priority: 0.7,
107+
changefreq: 'weekly'
108+
};
109+
},
110+
111+
// Exclude specific paths if needed
112+
exclude: ['/sitemap.xml', '/robots.txt'],
113+
114+
// Generate index sitemaps for better organization
115+
generateIndexSitemap: true,
116+
117+
// Robots txt configuration
118+
robotsTxtOptions: {
119+
policies: [
120+
{
121+
userAgent: '*',
122+
allow: '/',
123+
disallow: ['/api/', '/admin/']
124+
}
125+
],
126+
additionalSitemaps: [
127+
`${process.env.NEXT_PUBLIC_HOME_URL || "https://fastgpt.io"}/sitemap.xml`
128+
]
129+
}
7130
}

0 commit comments

Comments
 (0)