This commit is contained in:
AyrisAI
2026-07-11 16:23:11 +03:00
parent 0a2ab83028
commit 17915cd3d5
7 changed files with 79 additions and 133 deletions
+43 -11
View File
@@ -1,24 +1,56 @@
import { MetadataRoute } from 'next'
import { i18n } from './dictionaries'
import type { MetadataRoute } from 'next';
import { i18n } from './dictionaries';
import fs from 'fs';
import path from 'path';
export default function sitemap(): MetadataRoute.Sitemap {
const baseUrl = 'https://moygroup.com.tr'
const baseUrl = 'https://moygroup.com.tr';
// Public pages defined in the project
const pages = ['', '/kurumsal', '/galeri', '/iletisim', '/menu', '/sss']
// Dynamically scan the app/[lang] folder for pages
const langDir = path.join(process.cwd(), 'app/[lang]');
let subfolders: string[] = [];
const sitemapEntries: MetadataRoute.Sitemap = []
try {
if (fs.existsSync(langDir)) {
subfolders = fs.readdirSync(langDir).filter((file) => {
const filePath = path.join(langDir, file);
if (fs.statSync(filePath).isDirectory()) {
// Only include folders that contain a page.tsx file
return fs.existsSync(path.join(filePath, 'page.tsx'));
}
return false;
});
}
} catch (error) {
console.error('Error reading directories for sitemap:', error);
}
// Base page paths: home page ('') + dynamic folders
const pages = ['', ...subfolders.map((folder) => `/${folder}`)];
for (const locale of i18n.locales) {
for (const page of pages) {
const sitemapEntries: MetadataRoute.Sitemap = [];
for (const page of pages) {
// Generate language alternates for this page
const alternatesLanguages: Record<string, string> = {};
for (const locale of i18n.locales) {
alternatesLanguages[locale] = `${baseUrl}/${locale}${page}`;
}
// Add entries for all locales, providing localized alternates for each
for (const locale of i18n.locales) {
sitemapEntries.push({
url: `${baseUrl}/${locale}${page}`,
lastModified: new Date(),
changeFrequency: page === '' ? 'weekly' : 'monthly',
priority: page === '' ? 1 : 0.8,
})
priority: page === '' ? 1.0 : 0.8,
alternates: {
languages: alternatesLanguages,
},
});
}
}
return sitemapEntries
return sitemapEntries;
}