From 7d87d936adeee468549f11365764fd8e40f0f786 Mon Sep 17 00:00:00 2001 From: Web-serfer Date: Mon, 11 May 2026 23:59:47 +0500 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D1=82=D1=8C=20'=D0=92=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5'=20=E2=86=92=20SEO=20H2=20=D0=B4=D0=BB=D1=8F=208?= =?UTF-8?q?=20=D0=BF=D0=BE=D1=81=D1=82=D0=BE=D0=B2=20=D0=BD=D0=B0=20produc?= =?UTF-8?q?tion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Скрипт fix-introduction-h2.ts для массового исправления - Скрипт fix-last-post.ts для частного случая - Добавлены эмодзи в зависимости от категории поста Пофикшено 8 постов: - Скрытие с места ДТП - Отказ от подписи в протоколе ГИБДД - За рулем на лекарствах - Лишение прав за встречку - Независимая экспертиза после ДТП - Бесплатная консультация автоюриста - Протокол и постановление ГИБДД - 5 ошибок при заполнении протокола --- scripts/fix-introduction-h2.ts | 121 +++++++++++++++++++++++++++++++++ scripts/fix-last-post.ts | 23 +++++++ 2 files changed, 144 insertions(+) create mode 100644 scripts/fix-introduction-h2.ts create mode 100644 scripts/fix-last-post.ts diff --git a/scripts/fix-introduction-h2.ts b/scripts/fix-introduction-h2.ts new file mode 100644 index 0000000..e3965bd --- /dev/null +++ b/scripts/fix-introduction-h2.ts @@ -0,0 +1,121 @@ +import PocketBase from 'pocketbase'; + +const PB_URL = 'https://avt-back.ru'; +const ADMIN_EMAIL = 'redibedi2019@gmail.com'; +const ADMIN_PASSWORD = 'Stalin4444'; + +// Посты с "Введение" на production +const PROBLEMATIC_POSTS = [ + { + id: 'e8or2rfsrpoly19', + title: 'Скрытие с места ДТП', + slug: 'skrytie-s-mesta-dtp' + }, + { + id: 'no247l14oxw156i', + title: 'Отказ от подписи в протоколе ГИБДД', + slug: 'otkaz-ot-podpisi-v-protokole-gibdd' + }, + { + id: 'eflpgypt1r78q3q', + title: 'За рулем на лекарствах', + slug: 'lekarstva-za-rulem-lishenie-prav' + }, + { + id: 'kmt2cpiu47jsp9c', + title: 'Лишение прав за встречку', + slug: 'lishenie-prav-za-vstrechku-12-15' + }, + { + id: '87u3tnboztln5w1', + title: 'Независимая экспертиза после ДТП', + slug: 'nezavisimaya-ekspertiza-posle-dtp' + }, + { + id: 'ewq7fbjbgpo12iv', + title: 'Консультация автоюриста', + slug: 'avtoyurist-surgut-besplatnaya-konsultaciya' + }, + { + id: '656dhm888yebhc8', + title: 'Протокол и постановление ГИБДД', + slug: 'protocol-ili-postanovlenie' + }, + { + id: 'f54gic3amc1rmjx', + title: '5 ошибок при заполнении протокола', + slug: '5-oshibok-voditelya-pri-zapolnenii-protokola-gibdd' + } +]; + +// Эмодзи по категории (приблизительно) +function getEmojiForTitle(title: string): string { + const lower = title.toLowerCase(); + if (lower.includes('дтп') || lower.includes('авария') || lower.includes('столкновен')) return '⚖️'; + if (lower.includes('лишени') || lower.includes('прав')) return '🚗'; + if (lower.includes('протокол') || lower.includes('гибдд') || lower.includes('штраф')) return '📋'; + if (lower.includes('эксперт')) return '🔍'; + if (lower.includes('консульт')) return '💡'; + return '⚖️'; +} + +async function fixIntroductionH2() { + const pb = new PocketBase(PB_URL); + + try { + await pb.admins.authWithPassword(ADMIN_EMAIL, ADMIN_PASSWORD); + console.log('✅ Подключено к PocketBase\n'); + } catch (e) { + console.error('❌ Ошибка авторизации:', e); + process.exit(1); + } + + let fixed = 0; + let errors = 0; + + for (const post of PROBLEMATIC_POSTS) { + try { + // Получаем текущий пост + const current = await pb.collection('posts').getOne(post.id); + const content = current.content || ''; + + // Проверяем что действительно начинается с "Введение" + if (!content.includes('

Введение

') && !content.includes('

Введение ')) { + console.log(`⏭️ ${post.title} — уже исправлен или не содержит "Введение"`); + continue; + } + + // Формируем новый H2 + const newH2 = `

${getEmojiForTitle(post.title)} ${post.title}

`; + + // Заменяем "Введение" на новый H2 + // Учитываем возможные варианты:

Введение

,

Введение

, etc + const newContent = content.replace(/

\s*Введение\s*<\/h2>/gi, newH2); + + // Если замена не произошла, попробуем другой паттерн + const finalContent = newContent.includes(newH2) + ? newContent + : content.replace(/

[^<]*Введение[^<]*<\/h2>/gi, newH2); + + // Обновляем пост + await pb.collection('posts').update(post.id, { content: finalContent }); + + console.log(`✅ ${post.title}`); + console.log(` Было:

Введение

`); + console.log(` Стало: ${newH2}`); + console.log(` URL: https://avtourist-surgut.ru/blog/${post.slug}`); + console.log(); + + fixed++; + } catch (e: any) { + console.error(`❌ Ошибка при обработке ${post.title}:`, e.message); + errors++; + } + } + + console.log('='.repeat(50)); + console.log(`Готово! Исправлено: ${fixed}, ошибок: ${errors}`); + console.log('='.repeat(50)); +} + +fixIntroductionH2(); diff --git a/scripts/fix-last-post.ts b/scripts/fix-last-post.ts new file mode 100644 index 0000000..c498e2c --- /dev/null +++ b/scripts/fix-last-post.ts @@ -0,0 +1,23 @@ +import PocketBase from 'pocketbase'; + +const pb = new PocketBase('https://avt-back.ru'); +await pb.admins.authWithPassword('redibedi2019@gmail.com', 'Stalin4444'); + +const post = await pb.collection('posts').getOne('ewq7fbjbgpo12iv'); +const content = post.content || ''; + +console.log('Текущий H2:', content.match(/]*>[^<]*<\/h2>/i)?.[0]); + +// Исправляем

Введение

+const newContent = content.replace( + /\s*Введение\s*<\/h2>/gi, + '

💡 Бесплатная консультация автоюриста в Сургуте

' +); + +if (content === newContent) { + console.log('⚠️ Замена не произошла - проверь паттерн'); +} else { + await pb.collection('posts').update('ewq7fbjbgpo12iv', { content: newContent }); + console.log('✅ Исправлено!'); + console.log('URL: https://avtourist-surgut.ru/blog/avtoyurist-surgut-besplatnaya-konsultaciya'); +}