/* eslint-disable @typescript-eslint/no-require-imports */ /* eslint-disable no-undef */ const fs = require('fs'); const path = require('path'); // Контент для главной страницы const homeContent = `
Loading...

Сайт в разработке

`.trim(); // Функция для генерации полного HTML из terma.md const generateTermsContent = () => { const termaPath = path.resolve(__dirname, '../terma.md'); const termaText = fs.readFileSync(termaPath, 'utf-8'); // Парсим markdown в HTML с сохранением структуры let html = '
'; html += '
'; const lines = termaText.split('\n'); let inList = false; for (let i = 0; i < lines.length; i++) { const line = lines[i].trim(); if (!line) { if (inList) { html += ''; inList = false; } continue; } // Заголовок H1 if (i === 0) { html += '
'; html += `

${line}

`; continue; } // Дата обновления if (line.includes('Последнее обновление')) { html += `

${line}

`; html += '

'; continue; } // Основные разделы (начинаются с цифры и точки без подразделов) if (/^\d+\.\s+[А-Яа-я]/.test(line)) { if (inList) { html += ''; inList = false; } const text = line.replace(/^\d+\.\s+/, ''); html += `

${line}

`; continue; } // Подразделы (например, 2.1., 3.2.) if (/^\d+\.\d+\.\s+/.test(line)) { if (inList) { html += ''; inList = false; } html += `

${line}

`; continue; } // Списки (начинаются с заглавной буквы или содержат "—") if (line.includes('—') || (i > 0 && lines[i-1].includes('через:')) || (i > 0 && lines[i-1].includes('обязуется:')) || (i > 0 && lines[i-1].includes('собирает:')) || (i > 0 && lines[i-1].includes('ответственности за:'))) { if (!inList) { html += ''; inList = false; } // Обработка жирного текста и ссылок let processedLine = line .replace(/\*\*([^*]+)\*\*/g, '$1') .replace(/https?:\/\/[^\s,)]+/g, (url) => { const cleanUrl = url.replace(/\s*,?\s*$/, ''); return `${cleanUrl}`; }) .replace(/([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})/g, '$1'); html += `

${processedLine}

`; } if (inList) { html += ''; } // Footer html += '
'; html += '

© 2025 BROJS.RU. Все права защищены.

'; html += '
'; return html; }; const prerender = () => { try { console.log('🚀 Начинаем мульти-страничный пре-рендеринг...'); const distPath = path.resolve(__dirname, '../dist'); const indexPath = path.join(distPath, 'index.html'); // Читаем основной HTML let indexHtml = fs.readFileSync(indexPath, 'utf-8'); // 1. Обрабатываем главную страницу const searchString = '
'; if (indexHtml.includes(searchString)) { indexHtml = indexHtml.replace(searchString, `
${homeContent}
`); fs.writeFileSync(indexPath, indexHtml, 'utf-8'); console.log('✅ index.html обновлен'); } // 2. Генерируем полный контент для terms.html из terma.md console.log('📝 Генерируем полный HTML из terma.md...'); const termsContent = generateTermsContent(); // 3. Создаем terms.html на основе index.html let termsHtml = indexHtml .replace(homeContent, termsContent) .replace('bro-js admin', 'Пользовательское соглашение - BROJS.RU') .replace( '', '' ); const termsPath = path.join(distPath, 'terms.html'); fs.writeFileSync(termsPath, termsHtml, 'utf-8'); console.log('✅ terms.html создан с полным контентом'); console.log('🎉 Пре-рендеринг завершен успешно!'); console.log('📄 Созданы файлы: index.html, terms.html'); console.log('💡 terms.html содержит полный текст соглашения для SEO'); } catch (error) { console.error('❌ Ошибка при пре-рендеринге:', error); process.exit(1); } }; prerender();