astro_minivan/frontend/scripts/copy-sitemap.mjs
2026-05-07 00:11:27 +05:00

39 lines
No EOL
1.1 KiB
JavaScript

import { cpSync, existsSync, readFileSync, writeFileSync } from 'node:fs';
import { resolve, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const distDir = resolve(__dirname, '..', 'dist', 'client');
const source = resolve(distDir, 'sitemap-0.xml');
const target = resolve(distDir, 'sitemap.xml');
const excludeUrls = [
'/email-verified/',
'/auth/forgot-password/',
'/auth/reset-password/',
'/auth/verify-email/',
'/auth/login/',
'/auth/register/'
];
if (existsSync(source)) {
// Читаем sitemap
let content = readFileSync(source, 'utf-8');
// Удаляем исключённые URL
for (const url of excludeUrls) {
const fullUrl = `https://minivan-berlin.de${url}`;
content = content.replace(new RegExp(`<url><loc>${fullUrl}</loc></url>`, 'g'), '');
}
// Записываем очищенный sitemap
writeFileSync(source, content, 'utf-8');
console.log('✅ sitemap-0.xml cleaned');
// Копируем
cpSync(source, target);
console.log('✅ sitemap.xml created');
} else {
console.error('❌ sitemap-0.xml not found');
}