From 7d35b13e804c856fdd6528e89c71ab80e6debaf0 Mon Sep 17 00:00:00 2001 From: Yuriy Plotnikov Date: Mon, 18 May 2026 13:46:25 +0300 Subject: [PATCH] Fix sitemap --- src/app/sitemap.xml/route.ts | 78 +++++++++++++++++++----------------- src/lib/api-client.ts | 16 +------- 2 files changed, 43 insertions(+), 51 deletions(-) diff --git a/src/app/sitemap.xml/route.ts b/src/app/sitemap.xml/route.ts index 223dd93c..72d865b3 100644 --- a/src/app/sitemap.xml/route.ts +++ b/src/app/sitemap.xml/route.ts @@ -14,15 +14,15 @@ export async function GET() { const staticPages: SitemapUrl[] = [ { loc: `${siteUrl}/`, changefreq: 'daily', priority: 1.0 }, - { loc: `${siteUrl}/about`, changefreq: 'monthly', priority: 0.8 }, - { loc: `${siteUrl}/works`, changefreq: 'weekly', priority: 0.9 }, + { loc: `${siteUrl}/about`, changefreq: 'daily', priority: 0.9 }, + { loc: `${siteUrl}/works`, changefreq: 'daily', priority: 0.9 }, { loc: `${siteUrl}/in-stock`, changefreq: 'daily', priority: 0.9 }, - { loc: `${siteUrl}/contacts`, changefreq: 'monthly', priority: 0.8 }, - { loc: `${siteUrl}/categories`, changefreq: 'monthly', priority: 0.8 }, - { loc: `${siteUrl}/gallery`, changefreq: 'weekly', priority: 0.7 }, - { loc: `${siteUrl}/news`, changefreq: 'weekly', priority: 0.8 }, - { loc: `${siteUrl}/reviews`, changefreq: 'weekly', priority: 0.7 }, - { loc: `${siteUrl}/order-delivery`, changefreq: 'monthly', priority: 0.8 }, + { loc: `${siteUrl}/contacts`, changefreq: 'daily', priority: 0.9 }, + { loc: `${siteUrl}/categories`, changefreq: 'daily', priority: 0.9 }, + { loc: `${siteUrl}/gallery`, changefreq: 'daily', priority: 0.9 }, + { loc: `${siteUrl}/news`, changefreq: 'daily', priority: 0.9 }, + { loc: `${siteUrl}/reviews`, changefreq: 'daily', priority: 0.9 }, + { loc: `${siteUrl}/order-delivery`, changefreq: 'daily', priority: 0.9 }, ] const urls: SitemapUrl[] = [...staticPages] @@ -36,24 +36,24 @@ export async function GET() { ]) if (Array.isArray(works)) { - works.forEach((w: WorkFromServer) => { - if (w && (w.slug || w._id)) { + works.forEach((work: WorkFromServer) => { + if (work && (work.slug || work._id)) { urls.push({ - loc: `${siteUrl}/works/${w.slug || w._id}`, - lastmod: w._modified ? new Date(w._modified * 1000).toISOString() : undefined, - changefreq: 'monthly', - priority: 0.7, + loc: `${siteUrl}/works/${work.slug || work._id}`, + lastmod: work._modified ? new Date(work._modified * 1000).toISOString() : undefined, + changefreq: 'daily', + priority: 0.8, }) } }) } if (Array.isArray(inStock)) { - inStock.forEach((w: WorkFromServer) => { - if (w && (w.slug || w._id)) { + inStock.forEach((work: WorkFromServer) => { + if (work && (work.slug || work._id)) { urls.push({ - loc: `${siteUrl}/in-stock/${w.slug || w._id}`, - lastmod: w._modified ? new Date(w._modified * 1000).toISOString() : undefined, + loc: `${siteUrl}/in-stock/${work.slug || work._id}`, + lastmod: work._modified ? new Date(work._modified * 1000).toISOString() : undefined, changefreq: 'daily', priority: 0.8, }) @@ -62,42 +62,46 @@ export async function GET() { } if (Array.isArray(news)) { - news.forEach((n: NewsFromServer) => { - if (n && (n.slug || n._id)) { + news.forEach((item: NewsFromServer) => { + if (item && (item.slug || item._id)) { urls.push({ - loc: `${siteUrl}/news/${n.slug || n._id}`, - lastmod: n._modified ? new Date(n._modified * 1000).toISOString() : undefined, - changefreq: 'monthly', - priority: 0.6, + loc: `${siteUrl}/news/${item.slug || item._id}`, + lastmod: item._modified ? new Date(item._modified * 1000).toISOString() : undefined, + changefreq: 'daily', + priority: 0.8, }) } }) } if (Array.isArray(categories)) { - categories.forEach((c: CategoryFromServer) => { - if (c && (c.slug || c._id)) { + categories.forEach((category: CategoryFromServer) => { + if (category && (category.slug || category._id)) { urls.push({ - loc: `${siteUrl}/categories/${c.slug || c._id}`, - lastmod: c._modified ? new Date(c._modified * 1000).toISOString() : undefined, - changefreq: 'monthly', - priority: 0.7, + loc: `${siteUrl}/categories/${category.slug || category._id}`, + lastmod: category._modified ? new Date(category._modified * 1000).toISOString() : undefined, + changefreq: 'daily', + priority: 0.8, }) } }) } - } catch (e) { - console.error('Sitemap generation error:', e) + } catch (err) { + console.error('Sitemap generation error:', err) } const xml = ` - + ${urls .map( - (u) => ` - ${u.loc}${u.lastmod ? `\n ${u.lastmod}` : ''} - ${u.changefreq} - ${u.priority} + (url) => ` + ${url.loc} + ${url.lastmod ? `\n ${url.lastmod}` : ''} + ${url.changefreq} + ${url.priority} `, ) .join('\n')} diff --git a/src/lib/api-client.ts b/src/lib/api-client.ts index 276fb372..e17a22b4 100644 --- a/src/lib/api-client.ts +++ b/src/lib/api-client.ts @@ -17,18 +17,6 @@ interface FetchOptions { tags?: string[] } -/** - * Базовый URL для API запросов - * @returns базовый URL - */ -function getBaseUrl(): string { - if (typeof window === 'undefined') { - return process.env.INTERNAL_URL || 'http://localhost:3000' - } - - return window.location.origin -} - /** * Построение URL с учетом опций запроса * @param path - путь на сервере @@ -36,6 +24,7 @@ function getBaseUrl(): string { * @returns полный URL */ function buildUrl(path: string, options: FetchOptions = {}): string { + const baseUrl = process.env.INTERNAL_URL || 'http://localhost:3000' const params = new URLSearchParams() if (options.locale) params.set('locale', options.locale) @@ -47,7 +36,6 @@ function buildUrl(path: string, options: FetchOptions = {}): string { if (options.field) params.set('field', options.field) const queryString = params.toString() - const baseUrl = getBaseUrl() const fullPath = `${baseUrl}/api${path}` return queryString ? `${fullPath}?${queryString}` : fullPath @@ -215,11 +203,11 @@ export async function fetchCollectionCount( model: string, options: Pick = {}, ): Promise { + const baseUrl = process.env.INTERNAL_URL || 'http://localhost:3000' const params = new URLSearchParams() if (options.filter) params.set('filter', JSON.stringify(options.filter)) - const baseUrl = getBaseUrl() const queryString = params.toString() const url = `${baseUrl}/api/content/collection/${model}/count${queryString ? `?${queryString}` : ''}`