104 lines
2.9 KiB
TypeScript
104 lines
2.9 KiB
TypeScript
import { MetadataRoute } from 'next';
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
export default function sitemap(): MetadataRoute.Sitemap {
|
|
const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || 'https://your-domain.com';
|
|
|
|
// Static routes
|
|
const staticRoutes = [
|
|
{
|
|
url: baseUrl,
|
|
lastModified: new Date(),
|
|
changeFrequency: 'daily' as const,
|
|
priority: 1,
|
|
},
|
|
{
|
|
url: `${baseUrl}/products`,
|
|
lastModified: new Date(),
|
|
changeFrequency: 'weekly' as const,
|
|
priority: 0.8,
|
|
},
|
|
{
|
|
url: `${baseUrl}/products/ecs`,
|
|
lastModified: new Date(),
|
|
changeFrequency: 'weekly' as const,
|
|
priority: 0.7,
|
|
},
|
|
{
|
|
url: `${baseUrl}/products/oss`,
|
|
lastModified: new Date(),
|
|
changeFrequency: 'weekly' as const,
|
|
priority: 0.7,
|
|
},
|
|
{
|
|
url: `${baseUrl}/products/rds`,
|
|
lastModified: new Date(),
|
|
changeFrequency: 'weekly' as const,
|
|
priority: 0.7,
|
|
},
|
|
{
|
|
url: `${baseUrl}/products/slb`,
|
|
lastModified: new Date(),
|
|
changeFrequency: 'weekly' as const,
|
|
priority: 0.7,
|
|
},
|
|
{
|
|
url: `${baseUrl}/solutions`,
|
|
lastModified: new Date(),
|
|
changeFrequency: 'weekly' as const,
|
|
priority: 0.8,
|
|
},
|
|
{
|
|
url: `${baseUrl}/news`,
|
|
lastModified: new Date(),
|
|
changeFrequency: 'daily' as const,
|
|
priority: 0.8,
|
|
},
|
|
{
|
|
url: `${baseUrl}/contact`,
|
|
lastModified: new Date(),
|
|
changeFrequency: 'monthly' as const,
|
|
priority: 0.6,
|
|
},
|
|
{
|
|
url: `${baseUrl}/support`,
|
|
lastModified: new Date(),
|
|
changeFrequency: 'weekly' as const,
|
|
priority: 0.7,
|
|
},
|
|
];
|
|
|
|
// Dynamic news routes
|
|
const newsRoutes = getDynamicNewsRoutes(baseUrl);
|
|
|
|
return [...staticRoutes, ...newsRoutes];
|
|
}
|
|
|
|
function getDynamicNewsRoutes(baseUrl: string) {
|
|
const contentDir = path.join(process.cwd(), 'content');
|
|
const routes: MetadataRoute.Sitemap = [];
|
|
|
|
try {
|
|
if (fs.existsSync(contentDir)) {
|
|
const folders = fs
|
|
.readdirSync(contentDir, { withFileTypes: true })
|
|
.filter((dirent) => dirent.isDirectory())
|
|
.map((dirent) => dirent.name);
|
|
|
|
folders.forEach((folder) => {
|
|
routes.push({
|
|
url: `${baseUrl}/news/${folder}`,
|
|
lastModified: new Date(),
|
|
changeFrequency: 'weekly' as const,
|
|
priority: 0.6,
|
|
});
|
|
});
|
|
}
|
|
} catch (error) {
|
|
console.warn('Could not read content directory for sitemap generation:', error);
|
|
}
|
|
|
|
return routes;
|
|
}
|