109 lines
2.8 KiB
TypeScript
109 lines
2.8 KiB
TypeScript
// Utility functions for sitemap generation
|
|
|
|
export interface SitemapRoute {
|
|
url: string;
|
|
lastModified?: Date;
|
|
changeFrequency?: 'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never';
|
|
priority?: number;
|
|
alternates?: {
|
|
languages?: Record<string, string>;
|
|
};
|
|
}
|
|
|
|
// Supported languages
|
|
export const supportedLanguages = ['zh-CN', 'zh-TW', 'en'];
|
|
|
|
// Static routes configuration with multilingual support
|
|
export const staticRoutes: SitemapRoute[] = [
|
|
{
|
|
url: '',
|
|
lastModified: new Date(),
|
|
changeFrequency: 'daily',
|
|
priority: 1.0,
|
|
},
|
|
{
|
|
url: '/about',
|
|
lastModified: new Date(),
|
|
changeFrequency: 'monthly',
|
|
priority: 0.8,
|
|
},
|
|
{
|
|
url: '/products',
|
|
lastModified: new Date(),
|
|
changeFrequency: 'weekly',
|
|
priority: 0.9,
|
|
},
|
|
{
|
|
url: '/news',
|
|
lastModified: new Date(),
|
|
changeFrequency: 'daily',
|
|
priority: 0.8,
|
|
},
|
|
{
|
|
url: '/support',
|
|
lastModified: new Date(),
|
|
changeFrequency: 'weekly',
|
|
priority: 0.7,
|
|
},
|
|
{
|
|
url: '/contact',
|
|
lastModified: new Date(),
|
|
changeFrequency: 'monthly',
|
|
priority: 0.6,
|
|
},
|
|
];
|
|
|
|
// Article data with dates for sitemap
|
|
export const articlesMetadata = {
|
|
'1': {
|
|
lastModified: new Date('2025-02-10'),
|
|
priority: 0.7,
|
|
},
|
|
'2': {
|
|
lastModified: new Date('2025-02-24'),
|
|
priority: 0.7,
|
|
},
|
|
};
|
|
|
|
// Get all article IDs from the embedded data
|
|
export function getAllArticleIds(): string[] {
|
|
return Object.keys(articlesMetadata);
|
|
}
|
|
|
|
// Generate article routes
|
|
export function getArticleRoutes(): SitemapRoute[] {
|
|
const articleIds = getAllArticleIds();
|
|
|
|
return articleIds.map((id) => {
|
|
const metadata = articlesMetadata[id as keyof typeof articlesMetadata];
|
|
return {
|
|
url: `/news/${id}`,
|
|
lastModified: metadata.lastModified,
|
|
changeFrequency: 'monthly' as const,
|
|
priority: metadata.priority,
|
|
};
|
|
});
|
|
}
|
|
|
|
// Get the base URL from environment or default
|
|
export function getBaseUrl(): string {
|
|
// In production, you should set NEXT_PUBLIC_SITE_URL environment variable
|
|
return process.env.NEXT_PUBLIC_SITE_URL || 'https://dongyun.com';
|
|
}
|
|
|
|
// Generate language-specific routes (if needed for future implementation)
|
|
export function getLanguageRoutes(): SitemapRoute[] {
|
|
const routes: SitemapRoute[] = [];
|
|
|
|
// For now, we're not implementing language-specific URLs
|
|
// But this function is ready for future expansion
|
|
// Example: /en/about, /zh-tw/about, etc.
|
|
|
|
return routes;
|
|
}
|
|
|
|
// Get all routes combined
|
|
export function getAllRoutes(): SitemapRoute[] {
|
|
return [...staticRoutes, ...getArticleRoutes(), ...getLanguageRoutes()];
|
|
}
|