chore: clean up scratch files and apply remaining updates
This commit is contained in:
+83
-41
@@ -1,70 +1,112 @@
|
||||
import { MetadataRoute } from 'next'
|
||||
import { mockDb } from '@/lib/mockDb'
|
||||
import { SITE_URL, LOCALES } from '@/lib/seo'
|
||||
|
||||
function localizedEntries(
|
||||
pathSuffix: string,
|
||||
opts: {
|
||||
lastModified?: Date
|
||||
changeFrequency?: NonNullable<MetadataRoute.Sitemap[number]['changeFrequency']>
|
||||
priority?: number
|
||||
}
|
||||
): MetadataRoute.Sitemap {
|
||||
const languages: Record<string, string> = {}
|
||||
for (const locale of LOCALES) {
|
||||
languages[locale] = `${SITE_URL}/${locale}${pathSuffix}`
|
||||
}
|
||||
languages['x-default'] = `${SITE_URL}/tr${pathSuffix}`
|
||||
|
||||
return LOCALES.map((locale) => ({
|
||||
url: `${SITE_URL}/${locale}${pathSuffix}`,
|
||||
lastModified: opts.lastModified || new Date(),
|
||||
changeFrequency: opts.changeFrequency,
|
||||
priority: opts.priority,
|
||||
alternates: { languages },
|
||||
}))
|
||||
}
|
||||
|
||||
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
const baseUrl = 'https://marmarislocal.com'
|
||||
const locales = ['tr', 'en', 'ru']
|
||||
const entries: MetadataRoute.Sitemap = []
|
||||
|
||||
// Static routes
|
||||
const staticRoutes = [
|
||||
'',
|
||||
'/aparts',
|
||||
'/restaurants',
|
||||
'/businesses',
|
||||
'/add-business',
|
||||
'/contact',
|
||||
'/about'
|
||||
]
|
||||
// 1. Home
|
||||
entries.push(...localizedEntries('', { changeFrequency: 'weekly', priority: 1.0 }))
|
||||
|
||||
const sitemapEntries: MetadataRoute.Sitemap = []
|
||||
|
||||
// 1. Generate static routes for each locale
|
||||
// 2. Static routes
|
||||
const staticRoutes = ['/about', '/contact', '/add-business', '/collections', '/blog', '/events']
|
||||
for (const route of staticRoutes) {
|
||||
for (const locale of locales) {
|
||||
sitemapEntries.push({
|
||||
url: `${baseUrl}/${locale}${route}`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'weekly',
|
||||
priority: route === '' ? 1.0 : 0.8,
|
||||
})
|
||||
}
|
||||
entries.push(...localizedEntries(route, { changeFrequency: 'weekly', priority: 0.7 }))
|
||||
}
|
||||
|
||||
// 2. Dynamic listing routes
|
||||
// 3. Category landing pages (slugs are DB-driven, not hardcoded)
|
||||
try {
|
||||
const categories = await mockDb.getCategories()
|
||||
for (const category of categories) {
|
||||
entries.push(...localizedEntries(`/${category.slug}`, { changeFrequency: 'daily', priority: 0.8 }))
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Sitemap categories fetch error:', e)
|
||||
}
|
||||
|
||||
// 4. Listing detail pages
|
||||
try {
|
||||
const listings = await mockDb.getListings()
|
||||
for (const listing of listings) {
|
||||
// Find the category slug dynamically
|
||||
const catSlug = listing.category?.slug || 'isletmeler'
|
||||
for (const locale of locales) {
|
||||
sitemapEntries.push({
|
||||
url: `${baseUrl}/${locale}/${catSlug}/${listing.slug}`,
|
||||
lastModified: listing.updatedAt || new Date(),
|
||||
const catSlug = listing.category?.slug || 'isletme'
|
||||
entries.push(
|
||||
...localizedEntries(`/${catSlug}/${listing.slug}`, {
|
||||
lastModified: listing.updatedAt,
|
||||
changeFrequency: 'weekly',
|
||||
priority: 0.6,
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Sitemap listings fetch error:', e)
|
||||
}
|
||||
|
||||
// 3. Dynamic neighborhood routes
|
||||
// 5. Neighborhood pages
|
||||
try {
|
||||
const neighborhoods = await mockDb.getNeighborhoods()
|
||||
for (const neighborhood of neighborhoods) {
|
||||
for (const locale of locales) {
|
||||
sitemapEntries.push({
|
||||
url: `${baseUrl}/${locale}/neighborhood/${neighborhood.slug}`,
|
||||
lastModified: new Date(),
|
||||
changeFrequency: 'monthly',
|
||||
priority: 0.4,
|
||||
})
|
||||
}
|
||||
entries.push(
|
||||
...localizedEntries(`/neighborhood/${neighborhood.slug}`, { changeFrequency: 'monthly', priority: 0.4 })
|
||||
)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Sitemap neighborhoods fetch error:', e)
|
||||
}
|
||||
|
||||
return sitemapEntries
|
||||
// 6. Collections
|
||||
try {
|
||||
const collections = await mockDb.getCollections()
|
||||
for (const collection of collections) {
|
||||
entries.push(
|
||||
...localizedEntries(`/collection/${collection.slug}`, {
|
||||
lastModified: collection.updatedAt,
|
||||
changeFrequency: 'monthly',
|
||||
priority: 0.5,
|
||||
})
|
||||
)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Sitemap collections fetch error:', e)
|
||||
}
|
||||
|
||||
// 7. Blog posts
|
||||
try {
|
||||
const posts = await mockDb.getBlogPosts(true)
|
||||
for (const post of posts) {
|
||||
entries.push(
|
||||
...localizedEntries(`/blog/${post.slug}`, {
|
||||
lastModified: post.updatedAt,
|
||||
changeFrequency: 'monthly',
|
||||
priority: 0.5,
|
||||
})
|
||||
)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Sitemap blog posts fetch error:', e)
|
||||
}
|
||||
|
||||
return entries
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user