fix: Восстановлена генерация sitemap.xml

- Добавлен плагин автогенерации sitemap при сборке frontend
- Обновлен nginx.conf для fallback на backend sitemap
- Sitemap включает русские и английские версии всех страниц
- Поддержка hreflang для SEO
This commit is contained in:
2026-01-14 14:50:17 +03:00
parent 95780564a6
commit a408184851
4 changed files with 137 additions and 4 deletions

View File

@@ -1,12 +1,59 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { copyFileSync } from 'fs'
import { copyFileSync, writeFileSync } from 'fs'
import { dirname, resolve } from 'path'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
// Функция для генерации sitemap.xml
function generateSitemap() {
const baseUrl = 'https://ospab.host';
const lastmod = new Date().toISOString().split('T')[0];
const pages = [
{ loc: '/', priority: '1.0', changefreq: 'weekly' },
{ loc: '/about', priority: '0.9', changefreq: 'monthly' },
{ loc: '/login', priority: '0.7', changefreq: 'monthly' },
{ loc: '/register', priority: '0.8', changefreq: 'monthly' },
{ loc: '/blog', priority: '0.85', changefreq: 'daily' },
{ loc: '/tariffs', priority: '0.9', changefreq: 'weekly' },
{ loc: '/s3plans', priority: '0.9', changefreq: 'weekly' },
{ loc: '/terms', priority: '0.5', changefreq: 'yearly' },
{ loc: '/privacy', priority: '0.5', changefreq: 'yearly' },
];
let xml = '<?xml version="1.0" encoding="UTF-8"?>\n';
xml += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">\n';
for (const page of pages) {
// Русская версия (без префикса)
xml += ' <url>\n';
xml += ` <loc>${baseUrl}${page.loc}</loc>\n`;
xml += ` <lastmod>${lastmod}</lastmod>\n`;
xml += ` <priority>${page.priority}</priority>\n`;
xml += ` <changefreq>${page.changefreq}</changefreq>\n`;
xml += ` <xhtml:link rel="alternate" hreflang="ru" href="${baseUrl}${page.loc}"/>\n`;
xml += ` <xhtml:link rel="alternate" hreflang="en" href="${baseUrl}/en${page.loc}"/>\n`;
xml += ' </url>\n';
// Английская версия (с префиксом /en)
xml += ' <url>\n';
xml += ` <loc>${baseUrl}/en${page.loc}</loc>\n`;
xml += ` <lastmod>${lastmod}</lastmod>\n`;
xml += ` <priority>${page.priority}</priority>\n`;
xml += ` <changefreq>${page.changefreq}</changefreq>\n`;
xml += ` <xhtml:link rel="alternate" hreflang="ru" href="${baseUrl}${page.loc}"/>\n`;
xml += ` <xhtml:link rel="alternate" hreflang="en" href="${baseUrl}/en${page.loc}"/>\n`;
xml += ' </url>\n';
}
xml += '</urlset>';
return xml;
}
// https://vite.dev/config/
export default defineConfig({
plugins: [
@@ -25,6 +72,23 @@ export default defineConfig({
console.error('❌ Ошибка копирования service worker:', error)
}
}
},
{
name: 'generate-sitemap',
writeBundle() {
// Генерируем sitemap.xml при сборке
try {
const sitemapContent = generateSitemap();
writeFileSync(
resolve(__dirname, 'dist/sitemap.xml'),
sitemapContent,
'utf-8'
);
console.log('✅ Sitemap.xml сгенерирован в dist/');
} catch (error) {
console.error('❌ Ошибка генерации sitemap:', error);
}
}
}
],
build: {