From 872e8794ddbeff990624651e5dd6d740c10b9c1a Mon Sep 17 00:00:00 2001 From: Ruslan Semak Date: Fri, 25 Apr 2025 14:28:10 +0300 Subject: [PATCH] feat: Changed links renames strategy --- server/models/pages.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/server/models/pages.js b/server/models/pages.js index 11786b88..a29c61fa 100644 --- a/server/models/pages.js +++ b/server/models/pages.js @@ -393,18 +393,21 @@ module.exports = class Page extends Model { // На pageLinks опираться нельзя, т.r. авто-сгенерированные страницы не добавляются в pageLink if (opts.title && ogPage.title !== opts.title) { const allPages = await WIKI.models.pages.query() - const mentionedInPages = allPages.filter(page => page.content.includes(ogPage.path)) + const mentionedInPages = allPages.filter(page => page.content.includes(`data-page-id="${ogPage.id}"`)) for (const page of mentionedInPages) { - // const page = mentionedInPages.find(page => page.title.includes('Шаблон')) - const $ = cheerio.load(page.content) - const targetLinks = $(`a[href="/${ogPage.path}"]`) + const targetLinks = $(`a[data-page-id="${ogPage.id}"]`) let changed = false targetLinks.each((_, el) => { + if ('data-mention' in el.attribs) { + el.attribs['data-mention'] = `@${opts.title}` + changed = true + } + const $el = $(el) // Получаем все дочерние узлы (включая текстовые)