Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1614 Rendering of link color doesn't update until page with the link is saved again #7367

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions server/models/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -849,23 +849,54 @@ module.exports = class Page extends Model {
*/
static async reconnectLinks (opts) {
const pageHref = `/${opts.locale}/${opts.path}`
await this.reconnectLinksToSpecificHref({
path: opts.path,
locale: opts.locale,
pageHref: pageHref,
sourceHref: typeof opts.sourcePath !== 'undefined' ? `/${opts.sourceLocale}/${opts.sourcePath}` : undefined,
mode: opts.mode
})

if (opts.locale === WIKI.config.lang.code) {
const pageHrefWithoutLangCode = `/${opts.path}`
await this.reconnectLinksToSpecificHref({
path: opts.path,
locale: opts.locale,
pageHref: pageHrefWithoutLangCode,
sourceHref: typeof opts.sourcePath !== 'undefined' ? `/${opts.sourcePath}` : undefined,
mode: opts.mode
})
}
}

/**
* Reconnect links to new/move/deleted page
*
* @param {Object} opts - Page parameters
* @param {string} opts.path - Page Path
* @param {string} opts.locale - Page Locale Code
* @param {string} opts.pageHref - Page href (e.g. '/en/page', '/page')
* @param {string} [opts.sourceHref] - Previous Page Href (move only)
* @param {string} opts.mode - Page Update mode (create, move, delete)
* @returns {Promise} Promise with no value
*/
static async reconnectLinksToSpecificHref(opts) {
let replaceArgs = {
from: '',
to: ''
}
switch (opts.mode) {
case 'create':
replaceArgs.from = `<a href="${pageHref}" class="is-internal-link is-invalid-page">`
replaceArgs.to = `<a href="${pageHref}" class="is-internal-link is-valid-page">`
replaceArgs.from = `<a class="is-internal-link is-invalid-page" href="${opts.pageHref}">`
replaceArgs.to = `<a class="is-internal-link is-valid-page" href="${opts.pageHref}">`
break
case 'move':
const prevPageHref = `/${opts.sourceLocale}/${opts.sourcePath}`
replaceArgs.from = `<a href="${prevPageHref}" class="is-internal-link is-valid-page">`
replaceArgs.to = `<a href="${pageHref}" class="is-internal-link is-valid-page">`
replaceArgs.from = `<a class="is-internal-link is-valid-page" href="${opts.sourceHref}">`
replaceArgs.to = `<a class="is-internal-link is-valid-page" href="${opts.pageHref}">`
break
case 'delete':
replaceArgs.from = `<a href="${pageHref}" class="is-internal-link is-valid-page">`
replaceArgs.to = `<a href="${pageHref}" class="is-internal-link is-invalid-page">`
replaceArgs.from = `<a class="is-internal-link is-valid-page" href="${opts.pageHref}">`
replaceArgs.to = `<a class="is-internal-link is-invalid-page" href="${opts.pageHref}">`
break
default:
return false
Expand Down