fix: external comments template using incorrect page variables

This commit is contained in:
Nicolas Giard 2022-04-14 22:09:45 -04:00 committed by GitHub
parent 74887baa86
commit a647626a51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -525,14 +525,26 @@ router.get('/*', async (req, res, next) => {
}
// -> Inject comments variables
if (WIKI.config.features.featurePageComments && WIKI.data.commentProvider.codeTemplate) {
const shouldDisplayComments = WIKI.config.features.featurePageComments && WIKI.data.commentProvider.codeTemplate
const commentTmpl = shouldDisplayComments ? {
codeTemplate: WIKI.data.commentProvider.codeTemplate,
head: WIKI.data.commentProvider.head,
body: WIKI.data.commentProvider.body,
main: WIKI.data.commentProvider.main
} : {
codeTemplate: false,
head: null,
body: null,
main: ''
}
if (shouldDisplayComments) {
[
{ key: 'pageUrl', value: `${WIKI.config.host}/i/${page.id}` },
{ key: 'pageId', value: page.id }
].forEach((cfg) => {
WIKI.data.commentProvider.head = _.replace(WIKI.data.commentProvider.head, new RegExp(`{{${cfg.key}}}`, 'g'), cfg.value)
WIKI.data.commentProvider.body = _.replace(WIKI.data.commentProvider.body, new RegExp(`{{${cfg.key}}}`, 'g'), cfg.value)
WIKI.data.commentProvider.main = _.replace(WIKI.data.commentProvider.main, new RegExp(`{{${cfg.key}}}`, 'g'), cfg.value)
commentTmpl.head = _.replace(commentTmpl.head, new RegExp(`{{${cfg.key}}}`, 'g'), cfg.value)
commentTmpl.body = _.replace(commentTmpl.body, new RegExp(`{{${cfg.key}}}`, 'g'), cfg.value)
commentTmpl.main = _.replace(commentTmpl.main, new RegExp(`{{${cfg.key}}}`, 'g'), cfg.value)
})
}
@ -541,7 +553,7 @@ router.get('/*', async (req, res, next) => {
page,
sidebar,
injectCode,
comments: WIKI.data.commentProvider,
comments: commentTmpl,
effectivePermissions
})
}