multi-comments

This commit is contained in:
xaoxuu 2022-11-14 00:28:48 +08:00
parent 8c8d3c1707
commit adf73dd5ce
5 changed files with 49 additions and 89 deletions

View File

@ -1,37 +1,18 @@
<% <%
function layoutDiv() { 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 = ''; var el = '';
el += '<div id="' + cmt + '"'; const cmt = page.cmt;
for (let key of Object.keys(config)) { if (cmt && cmt.service && (cmt.service.length > 0)) {
if (config[key] !== null) { const name = cmt.service;
el += ' ' + key + '="' + config[key] + '"'; const body = cmt[name];
el += '<div id="' + name + '"';
for (let key of Object.keys(body)) {
if (body[key] !== null) {
el += ' ' + key + '="' + body[key] + '"';
} }
} }
el += '></div>'; el += '></div>';
}
return el; return el;
} }
%> %>

View File

@ -1,35 +1,18 @@
<% <%
function layoutDiv() { 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 = ''; var el = '';
el += '<div id="' + cmt + '"'; const cmt = page.cmt;
for (let key of Object.keys(config)) { if (cmt && cmt.service && (cmt.service.length > 0)) {
if (config[key] !== null) { const name = cmt.service;
el += ' ' + key + '="' + config[key] + '"'; const body = cmt[name];
el += '<div id="' + name + '"';
for (let key of Object.keys(body)) {
if (body[key] !== null) {
el += ' ' + key + '="' + body[key] + '"';
} }
} }
el += '></div>'; el += '></div>';
}
return el; return el;
} }
%> %>

View File

@ -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; var loadComment = false;
if (theme.comments.service && theme.comments.service.length > 0) { if (theme.comments.service && theme.comments.service.length > 0) {
if (page.comments == undefined || page.comments != false) { if (page.comments == undefined || page.comments != false) {
@ -13,15 +19,24 @@ if (loadComment && page.layout == 'wiki' && page.wiki) {
page.comment_title = proj.comment_title; 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) { %> <% if (loadComment) { %>
<div class='related-wrap md reveal' id="comments"> <div class='related-wrap md reveal' id="comments">
<div class='cmt-title cap theme'> <div class='cmt-title cap theme'>
<%- page.comment_title != undefined ? markdown(page.comment_title) : __('meta.comment_title') %> <%- page.comment_title != undefined ? markdown(page.comment_title) : __('meta.comment_title') %>
</div> </div>
<div class='cmt-body <%- theme.comments.service %>'> <div class='cmt-body <%- cmt.service %>'>
<%- partial(theme.comments.service + '/layout') %> <%- partial(cmt.service + '/layout') %>
</div> </div>
</div> </div>
<% } %> <% } %>

View File

@ -1,3 +1,3 @@
<% if (theme.comments.service && theme.comments.service.length > 0) { %> <% if (page.cmt && page.cmt.service && page.cmt.service.length > 0) { %>
<%- partial(theme.comments.service + '/script') %> <%- partial(page.cmt.service + '/script') %>
<% } %> <% } %>

View File

@ -1,37 +1,18 @@
<% <%
function layoutDiv() { function layoutDiv() {
const cmt = 'utterances';
// 合并配置参数
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 = ''; var el = '';
el += '<div id="' + cmt + '"'; const cmt = page.cmt;
for (let key of Object.keys(config)) { if (cmt && cmt.service && (cmt.service.length > 0)) {
if (config[key] !== null) { const name = cmt.service;
el += ' ' + key + '="' + config[key] + '"'; const body = cmt[name];
el += '<div id="' + name + '"';
for (let key of Object.keys(body)) {
if (body[key] !== null) {
el += ' ' + key + '="' + body[key] + '"';
} }
} }
el += '></div>'; el += '></div>';
}
return el; return el;
} }
%> %>