From edd11cd73fb8782d2fcd8a723f70db0afe02ac21 Mon Sep 17 00:00:00 2001 From: NGPixel Date: Thu, 2 Jan 2020 20:30:48 -0500 Subject: [PATCH] feat: make relative links root absolute option --- server/modules/rendering/html-core/definition.yml | 8 +++++++- server/modules/rendering/html-core/renderer.js | 12 ++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/server/modules/rendering/html-core/definition.yml b/server/modules/rendering/html-core/definition.yml index 5283547e..f8f5f3f0 100644 --- a/server/modules/rendering/html-core/definition.yml +++ b/server/modules/rendering/html-core/definition.yml @@ -5,4 +5,10 @@ author: requarks.io input: html output: html icon: mdi-language-html5 -props: {} +props: + absoluteLinks: + type: Boolean + default: false + title: Treat relative links as root absolute + hint: For example, a link to foo/bar on page xyz will render as /foo/bar instead of /xyz/foo/bar. + order: 1 diff --git a/server/modules/rendering/html-core/renderer.js b/server/modules/rendering/html-core/renderer.js index 9551d7f4..233ccf19 100644 --- a/server/modules/rendering/html-core/renderer.js +++ b/server/modules/rendering/html-core/renderer.js @@ -69,7 +69,11 @@ module.exports = { if (WIKI.config.lang.namespacing) { // -> Reformat paths if (href.indexOf('/') !== 0) { - href = (this.page.path === 'home') ? `/${this.page.localeCode}/${href}` : `/${this.page.localeCode}/${this.page.path}/${href}` + if (this.config.absoluteLinks) { + href = `/${this.page.localeCode}/${href}` + } else { + href = (this.page.path === 'home') ? `/${this.page.localeCode}/${href}` : `/${this.page.localeCode}/${this.page.path}/${href}` + } } else if (href.charAt(3) !== '/') { href = `/${this.page.localeCode}${href}` } @@ -83,7 +87,11 @@ module.exports = { } else { // -> Reformat paths if (href.indexOf('/') !== 0) { - href = (this.page.path === 'home') ? `/${href}` : `/${this.page.path}/${href}` + if (this.config.absoluteLinks) { + href = `/${href}` + } else { + href = (this.page.path === 'home') ? `/${href}` : `/${this.page.path}/${href}` + } } try {