Просмотр исходного кода

fix: external comments template using incorrect page variables

Nicolas Giard 3 лет назад
Родитель
Сommit
a647626a51
1 измененных файлов с 17 добавлено и 5 удалено
  1. 17 5
      server/controllers/common.js

+ 17 - 5
server/controllers/common.js

@@ -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
           })
         }