feat: Changed links renames strategy

pull/7619/head
Ruslan Semak 7 months ago
parent eadc1bfe99
commit 872e8794dd

@ -393,18 +393,21 @@ module.exports = class Page extends Model {
// На pageLinks опираться нельзя, т.r. авто-сгенерированные страницы не добавляются в pageLink // На pageLinks опираться нельзя, т.r. авто-сгенерированные страницы не добавляются в pageLink
if (opts.title && ogPage.title !== opts.title) { if (opts.title && ogPage.title !== opts.title) {
const allPages = await WIKI.models.pages.query() 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) { for (const page of mentionedInPages) {
// const page = mentionedInPages.find(page => page.title.includes('Шаблон'))
const $ = cheerio.load(page.content) const $ = cheerio.load(page.content)
const targetLinks = $(`a[href="/${ogPage.path}"]`) const targetLinks = $(`a[data-page-id="${ogPage.id}"]`)
let changed = false let changed = false
targetLinks.each((_, el) => { targetLinks.each((_, el) => {
if ('data-mention' in el.attribs) {
el.attribs['data-mention'] = `@${opts.title}`
changed = true
}
const $el = $(el) const $el = $(el)
// Получаем все дочерние узлы (включая текстовые) // Получаем все дочерние узлы (включая текстовые)

Loading…
Cancel
Save