|
|
|
|
@ -395,9 +395,13 @@ module.exports = class Page extends Model {
|
|
|
|
|
const allPages = await WIKI.models.pages.query()
|
|
|
|
|
const mentionedInPages = allPages.filter(page => page.content.includes(ogPage.path))
|
|
|
|
|
|
|
|
|
|
for (const page of mentionedInPages) {
|
|
|
|
|
// const page = mentionedInPages.find(page => page.title.includes('Шаблон'))
|
|
|
|
|
const batch = 5
|
|
|
|
|
const iterations = Math.ceil(mentionedInPages.length / batch)
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < iterations; i++) {
|
|
|
|
|
const batchPages = mentionedInPages.slice(i * batch, i * batch + batch)
|
|
|
|
|
|
|
|
|
|
await Promise.all(batchPages.map(async (page) => {
|
|
|
|
|
const $ = cheerio.load(page.content)
|
|
|
|
|
|
|
|
|
|
const targetLinks = $(`a[href="/${ogPage.path}"]`)
|
|
|
|
|
@ -407,10 +411,8 @@ module.exports = class Page extends Model {
|
|
|
|
|
targetLinks.each((_, el) => {
|
|
|
|
|
const $el = $(el)
|
|
|
|
|
|
|
|
|
|
// Получаем все дочерние узлы (включая текстовые)
|
|
|
|
|
const contents = $el.contents()
|
|
|
|
|
|
|
|
|
|
// Рекурсивная функция для поиска и замены текста
|
|
|
|
|
const replaceText = (nodes) => {
|
|
|
|
|
nodes.each((_, node) => {
|
|
|
|
|
if (node.type === 'text') {
|
|
|
|
|
@ -437,6 +439,7 @@ module.exports = class Page extends Model {
|
|
|
|
|
await WIKI.models.pages.renderPage(page)
|
|
|
|
|
WIKI.events.outbound.emit('deletePageFromCache', page.hash)
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|