Версия 1.2.2 Начало посторения SEO через react-snap - добывлен скрипт для получения id всех статей..

This commit is contained in:
anibilag 2025-10-27 19:34:50 +03:00
parent 44fa4525f6
commit 6288d1f041
3 changed files with 2059 additions and 114 deletions

2114
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
{
"name": "vite-react-typescript-starter",
"private": true,
"version": "1.2.0",
"version": "1.2.2",
"type": "module",
"scripts": {
"dev": "vite",
@ -11,11 +11,17 @@
"server": "node server/index.js",
"prisma-seed": "npx prisma db seed",
"db:seed": "node prisma/seed.js",
"generate-sitemap": "node scripts/generate-sitemap.js"
"generate-sitemap": "node scripts/generate-sitemap.js",
"postbuild": "node scripts/generate-routes.js && npx react-snap"
},
"prisma": {
"seed": "npx ts-node --project tsconfig.node.json --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts"
},
"reactSnap": {
"source": "dist",
"inlineCss": true,
"skipThirdPartyRequests": true
},
"dependencies": {
"@aws-sdk/client-s3": "^3.525.0",
"@aws-sdk/s3-request-presigner": "^3.525.0",
@ -73,6 +79,8 @@
"globals": "^15.9.0",
"postcss": "^8.4.49",
"prisma": "^6.2.1",
"puppeteer": "^24.26.1",
"react-snap": "^1.13.1",
"tailwindcss": "^3.4.17",
"typescript": "^5.5.3",
"typescript-eslint": "^8.3.0",

View File

@ -0,0 +1,47 @@
import fs from "fs";
import axios from "axios";
async function main() {
const API_URL = 'http://localhost:5000';
async function fetchArticlePaths() {
try {
const response = await axios.get(`${API_URL}/api/articles/sitemap`);
return response.data.articles;
} catch (error) {
console.error('Ошибка при получении путей статей:', error.message);
return [];
}
}
const articles = await fetchArticlePaths();
// Базовые маршруты
const routes = ["/", "/about", "/articles"];
// Добавляем статьи
for (const row of articles) {
routes.push(`/article/${row.id}`);
}
// Загружаем шаблон react-snap конфигурации
const baseConfig = {
inlineCss: true,
source: "dist",
skipThirdPartyRequests: true,
routes
};
// Сохраняем в отдельный файл
fs.writeFileSync("./react-snap.config.js",
`export default ${JSON.stringify(baseConfig, null, 2)};\n`
);
console.log(`✅ Добавлено ${routes.length} маршрутов для react-snap`);
}
main().catch(err => {
console.error("❌ Ошибка:", err);
process.exit(1);
});