diff --git a/frontend/application/app/robots.ts b/frontend/application/app/robots.ts new file mode 100644 index 0000000..daf1ed2 --- /dev/null +++ b/frontend/application/app/robots.ts @@ -0,0 +1,19 @@ +import { MetadataRoute } from 'next'; + +export default function robots(): MetadataRoute.Robots { + const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || 'https://canina-iran.com'; + + return { + rules: { + userAgent: '*', + allow: '/', + disallow: [ + '/dashboard/', + '/checkout/', + '/profile/', + '/api/' + ], + }, + sitemap: `${baseUrl}/sitemap.xml`, + }; +} diff --git a/frontend/application/app/sitemap.ts b/frontend/application/app/sitemap.ts new file mode 100644 index 0000000..d1bb813 --- /dev/null +++ b/frontend/application/app/sitemap.ts @@ -0,0 +1,56 @@ +import { MetadataRoute } from 'next'; +import { productService } from '../lib/services/productService'; + +export default async function sitemap(): Promise { + const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || 'https://canina-iran.com'; + + // Static routes + const staticRoutes: MetadataRoute.Sitemap = [ + { + url: `${baseUrl}`, + lastModified: new Date(), + changeFrequency: 'daily', + priority: 1, + }, + { + url: `${baseUrl}/shop`, + lastModified: new Date(), + changeFrequency: 'daily', + priority: 0.9, + }, + { + url: `${baseUrl}/wiki`, + lastModified: new Date(), + changeFrequency: 'weekly', + priority: 0.8, + }, + { + url: `${baseUrl}/blog`, + lastModified: new Date(), + changeFrequency: 'weekly', + priority: 0.8, + }, + { + url: `${baseUrl}/search`, + lastModified: new Date(), + changeFrequency: 'weekly', + priority: 0.5, + }, + ]; + + // Dynamic products + try { + const products = await productService.getProducts(); + const productRoutes: MetadataRoute.Sitemap = products.map((product) => ({ + url: `${baseUrl}/shop/${product.id}`, + lastModified: new Date(), + changeFrequency: 'weekly', + priority: 0.7, + })); + + return [...staticRoutes, ...productRoutes]; + } catch (error) { + console.error("Failed to generate product sitemap:", error); + return staticRoutes; + } +}