x
This commit is contained in:
1 parent
3c4bb06003
commit
f7aa4d099f
36 files changed
+528
-180
No files matched your search
@@ -0,0 +1,78 @@
|
||||
import { MetadataRoute } from 'next';
|
||||
import { getCategories, getProducts, getArticlesResult } from '../lib/cms';
|
||||
|
||||
const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || 'http://localhost:3000';
|
||||
|
||||
const languages = ['th', 'en', 'ja', 'zh', 'vi', 'ko'];
|
||||
|
||||
function createAlternates(path: string) {
|
||||
const alternates: Record<string, string> = {};
|
||||
for (const lang of languages) {
|
||||
alternates[lang] = `${baseUrl}/${lang}${path}`;
|
||||
}
|
||||
return alternates;
|
||||
}
|
||||
|
||||
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
const [categories, products, articlesResult] = await Promise.all([
|
||||
getCategories(),
|
||||
getProducts('limit=1000'),
|
||||
getArticlesResult(),
|
||||
]);
|
||||
|
||||
const staticPages = [
|
||||
'',
|
||||
'/shop',
|
||||
'/scent-guide',
|
||||
'/about',
|
||||
'/contact',
|
||||
'/faq',
|
||||
];
|
||||
|
||||
const routes: MetadataRoute.Sitemap = staticPages.map((route) => ({
|
||||
url: `${baseUrl}/th${route}`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'daily',
|
||||
priority: route === '' ? 1 : 0.8,
|
||||
alternates: {
|
||||
languages: createAlternates(route),
|
||||
},
|
||||
}));
|
||||
|
||||
const categoryRoutes: MetadataRoute.Sitemap = categories.map((category) => ({
|
||||
url: `${baseUrl}/th/category/${category.id}`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'weekly',
|
||||
priority: 0.7,
|
||||
alternates: {
|
||||
languages: createAlternates(`/category/${category.id}`),
|
||||
},
|
||||
}));
|
||||
|
||||
const productRoutes: MetadataRoute.Sitemap = products.map((product) => ({
|
||||
url: `${baseUrl}/th/products/${product.id}`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'daily',
|
||||
priority: 0.9,
|
||||
alternates: {
|
||||
languages: createAlternates(`/products/${product.id}`),
|
||||
},
|
||||
}));
|
||||
|
||||
const articleRoutes: MetadataRoute.Sitemap = [];
|
||||
if (articlesResult.ok && articlesResult.data) {
|
||||
articlesResult.data.forEach((article) => {
|
||||
articleRoutes.push({
|
||||
url: `${baseUrl}/th/article/${article.slug}`,
|
||||
lastModified: new Date(article.updatedAt || article.createdAt),
|
||||
changeFrequency: 'monthly',
|
||||
priority: 0.6,
|
||||
alternates: {
|
||||
languages: createAlternates(`/article/${article.slug}`),
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return [...routes, ...categoryRoutes, ...productRoutes, ...articleRoutes];
|
||||
}
|
||||
Reference in new issue
Block a user