fix: исправить 'Введение' → SEO H2 для 8 постов на production
- Скрипт fix-introduction-h2.ts для массового исправления - Скрипт fix-last-post.ts для частного случая - Добавлены эмодзи в зависимости от категории поста Пофикшено 8 постов: - Скрытие с места ДТП - Отказ от подписи в протоколе ГИБДД - За рулем на лекарствах - Лишение прав за встречку - Независимая экспертиза после ДТП - Бесплатная консультация автоюриста - Протокол и постановление ГИБДД - 5 ошибок при заполнении протокола
This commit is contained in:
parent
9ad9fe4927
commit
7d87d936ad
2 changed files with 144 additions and 0 deletions
121
scripts/fix-introduction-h2.ts
Normal file
121
scripts/fix-introduction-h2.ts
Normal file
|
|
@ -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('<h2>Введение</h2>') && !content.includes('<h2>Введение ')) {
|
||||||
|
console.log(`⏭️ ${post.title} — уже исправлен или не содержит "Введение"`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Формируем новый H2
|
||||||
|
const newH2 = `<h2>${getEmojiForTitle(post.title)} ${post.title}</h2>`;
|
||||||
|
|
||||||
|
// Заменяем "Введение" на новый H2
|
||||||
|
// Учитываем возможные варианты: <h2>Введение</h2>, <h2>Введение </h2>, etc
|
||||||
|
const newContent = content.replace(/<h2>\s*Введение\s*<\/h2>/gi, newH2);
|
||||||
|
|
||||||
|
// Если замена не произошла, попробуем другой паттерн
|
||||||
|
const finalContent = newContent.includes(newH2)
|
||||||
|
? newContent
|
||||||
|
: content.replace(/<h2>[^<]*Введение[^<]*<\/h2>/gi, newH2);
|
||||||
|
|
||||||
|
// Обновляем пост
|
||||||
|
await pb.collection('posts').update(post.id, { content: finalContent });
|
||||||
|
|
||||||
|
console.log(`✅ ${post.title}`);
|
||||||
|
console.log(` Было: <h2>Введение</h2>`);
|
||||||
|
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();
|
||||||
23
scripts/fix-last-post.ts
Normal file
23
scripts/fix-last-post.ts
Normal file
|
|
@ -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[^>]*>[^<]*<\/h2>/i)?.[0]);
|
||||||
|
|
||||||
|
// Исправляем <h2 style="...">Введение</h2>
|
||||||
|
const newContent = content.replace(
|
||||||
|
/<h2\s+style="[^"]*">\s*Введение\s*<\/h2>/gi,
|
||||||
|
'<h2>💡 Бесплатная консультация автоюриста в Сургуте</h2>'
|
||||||
|
);
|
||||||
|
|
||||||
|
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');
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue