From adf73dd5ce9f2c9aa28934b2937f3479f3f2c188 Mon Sep 17 00:00:00 2001 From: xaoxuu Date: Mon, 14 Nov 2022 00:28:48 +0800 Subject: [PATCH] multi-comments --- .../plugins/comments/beaudar/layout.ejs | 39 +++++-------------- .../plugins/comments/giscus/layout.ejs | 37 +++++------------- layout/_partial/plugins/comments/layout.ejs | 19 ++++++++- layout/_partial/plugins/comments/script.ejs | 4 +- .../plugins/comments/utterances/layout.ejs | 39 +++++-------------- 5 files changed, 49 insertions(+), 89 deletions(-) diff --git a/layout/_partial/plugins/comments/beaudar/layout.ejs b/layout/_partial/plugins/comments/beaudar/layout.ejs index 4b0cbee..48dc222 100644 --- a/layout/_partial/plugins/comments/beaudar/layout.ejs +++ b/layout/_partial/plugins/comments/beaudar/layout.ejs @@ -1,37 +1,18 @@ <% function layoutDiv() { - const cmt = 'beaudar'; - // 合并配置参数 - var config = Object.assign({}, theme.comments[cmt]); - if (page.layout === 'wiki' && page.wiki) { - let proj = theme.wiki.projects[page.wiki]; - if (proj[cmt] != undefined) { - Object.assign(config, proj[cmt]); - } - } - Object.assign(config, page[cmt]); - // 合并评论数据 - if (config['issue-number'] !== null) { - config['issue-term'] = null; - } else { - if (page.comment_id != undefined) { - config['issue-term'] = page.comment_id; - } else if (page.layout === 'wiki' && page.wiki) { - let proj = theme.wiki.projects[page.wiki]; - if (proj.comment_id != undefined) { - config['issue-term'] = proj.comment_id; + var el = ''; + const cmt = page.cmt; + if (cmt && cmt.service && (cmt.service.length > 0)) { + const name = cmt.service; + const body = cmt[name]; + el += '
diff --git a/layout/_partial/plugins/comments/giscus/layout.ejs b/layout/_partial/plugins/comments/giscus/layout.ejs index 23af6b4..48dc222 100644 --- a/layout/_partial/plugins/comments/giscus/layout.ejs +++ b/layout/_partial/plugins/comments/giscus/layout.ejs @@ -1,35 +1,18 @@ <% function layoutDiv() { - const cmt = 'giscus'; - // 合并配置参数 - var config = Object.assign({}, theme.comments[cmt]); - if (page.layout === 'wiki' && page.wiki) { - let proj = theme.wiki.projects[page.wiki]; - if (proj[cmt] != undefined) { - Object.assign(config, proj[cmt]); - } - } - Object.assign(config, page[cmt]); - // 合并评论数据 - if (page.comment_id != undefined) { - config['data-mapping'] = 'specific'; - config['data-term'] = page.comment_id; - } else if (page.layout === 'wiki' && page.wiki) { - let proj = theme.wiki.projects[page.wiki]; - if (proj.comment_id != undefined) { - config['data-mapping'] = 'specific'; - config['data-term'] = proj.comment_id; - } - } - // 布局 var el = ''; - el += '
0)) { + const name = cmt.service; + const body = cmt[name]; + el += '
diff --git a/layout/_partial/plugins/comments/layout.ejs b/layout/_partial/plugins/comments/layout.ejs index 25c6b63..2cbf6c7 100644 --- a/layout/_partial/plugins/comments/layout.ejs +++ b/layout/_partial/plugins/comments/layout.ejs @@ -1,4 +1,10 @@ <% +var cmt = { + service: theme.comments.service +}; +if (cmt.service) { + cmt[cmt.service] = Object.assign({}, theme.comments[cmt.service]); +} var loadComment = false; if (theme.comments.service && theme.comments.service.length > 0) { if (page.comments == undefined || page.comments != false) { @@ -13,15 +19,24 @@ if (loadComment && page.layout == 'wiki' && page.wiki) { page.comment_title = proj.comment_title; } } + if (proj.comments && proj.comments.service) { + cmt = proj.comments; + let s = proj.comments.service; + cmt[s] = Object.assign({}, theme.comments[s], proj.comments[s]); + } } +if (cmt.service && page[cmt.service]) { + Object.assign(cmt[cmt.service], page[cmt.service]); +} +page.cmt = cmt; %> <% if (loadComment) { %>