feat: add waline comment system (#80)
This commit is contained in:
parent
8ab2eb9f94
commit
109c24c6d0
49
_config.yml
49
_config.yml
|
@ -87,7 +87,7 @@ article:
|
|||
|
||||
######## Comments ########
|
||||
comments:
|
||||
service: # beaudar, utterances, valine, twikoo
|
||||
service: # beaudar, utterances, valine, twikoo, waline
|
||||
# beaudar
|
||||
# https://beaudar.lipk.org/
|
||||
beaudar:
|
||||
|
@ -136,6 +136,52 @@ comments:
|
|||
twikoo:
|
||||
js: https://cdn.jsdelivr.net/npm/twikoo@1.4.0/dist/twikoo.all.min.js # 建议锁定版本
|
||||
envId: https://xxx # vercel函数
|
||||
waline:
|
||||
js: https://unpkg.com/@waline/client@v2/dist/waline.js
|
||||
css: https://unpkg.com/@waline/client@v2/dist/waline.css
|
||||
# Waline server address url, you should set this to your own link
|
||||
serverURL:
|
||||
|
||||
# If false, comment count will only be displayed in post page, not in home page
|
||||
commentCount: true
|
||||
|
||||
# Pageviews count, Note: You should not enable both `waline.pageview` and `leancloud_visitors`.
|
||||
pageview: false
|
||||
|
||||
# Custom locales
|
||||
# locale:
|
||||
# placeholder: Welcome to comment # Comment box placeholder
|
||||
|
||||
# Custom emoji
|
||||
# emoji:
|
||||
# - https://unpkg.com/@waline/emojis@1.0.1/weibo
|
||||
# - https://unpkg.com/@waline/emojis@1.0.1/alus
|
||||
# - https://unpkg.com/@waline/emojis@1.0.1/bilibili
|
||||
# - https://unpkg.com/@waline/emojis@1.0.1/qq
|
||||
# - https://unpkg.com/@waline/emojis@1.0.1/tieba
|
||||
# - https://unpkg.com/@waline/emojis@1.0.1/tw-emoji
|
||||
|
||||
# Comment infomation, valid meta are nick, mail and link
|
||||
# meta:
|
||||
# - nick
|
||||
# - mail
|
||||
# - link
|
||||
|
||||
# Set required meta field, e.g.: [nick] | [nick, mail]
|
||||
# requiredMeta:
|
||||
# - nick
|
||||
|
||||
# Language, available values: en-US, zh-CN, zh-TW, pt-BR, ru-RU, jp-JP
|
||||
# lang: zh-CN
|
||||
|
||||
# Word limit, no limit when setting to 0
|
||||
# wordLimit: 0
|
||||
|
||||
# Whether enable login, can choose from 'enable', 'disable' and 'force'
|
||||
# login: enable
|
||||
|
||||
# comment per page
|
||||
# pageSize: 10
|
||||
|
||||
######## Footer ########
|
||||
footer:
|
||||
|
@ -241,6 +287,7 @@ plugins:
|
|||
# 可以处理评论区的图片(不支持 iframe 类评论系统)例如:
|
||||
# 使用valine评论可以写: .vcontent img:not(.vemoji)
|
||||
# 使用twikoo评论可以写: .tk-content img:not([class*="emo"])
|
||||
# 使用waline评论可以写: #waline_container .vcontent img
|
||||
selector: .swiper-slide img # 多个选择器用英文逗号隔开
|
||||
|
||||
# swiper
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
<%
|
||||
function layoutDiv() {
|
||||
var el = '';
|
||||
el += '<div id="waline_container" class="waline_thread"';
|
||||
let cfg = {};
|
||||
if (page.comment_id) {
|
||||
cfg['comment_id'] = page.comment_id;
|
||||
}
|
||||
for (let key of Object.keys(cfg)) {
|
||||
if (cfg[key]) {
|
||||
el += ' ' + key + '="' + cfg[key] + '"';
|
||||
}
|
||||
}
|
||||
el += '><svg class="loading" style="vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2709"><path d="M832 512c0-176-144-320-320-320V128c211.2 0 384 172.8 384 384h-64zM192 512c0 176 144 320 320 320v64C300.8 896 128 723.2 128 512h64z" p-id="2710"></path></svg></div>';
|
||||
return el;
|
||||
}
|
||||
%>
|
||||
|
||||
<%- layoutDiv() %>
|
|
@ -0,0 +1,22 @@
|
|||
<script>
|
||||
function load_comment(){
|
||||
if(!document.getElementById("waline_container"))return;
|
||||
stellar.loadCSS('<%- theme.comments.waline.css %>');
|
||||
stellar.loadScript('<%- theme.comments.waline.js %>', {defer:true}).then(function () {
|
||||
const el = document.getElementById("waline_container");
|
||||
var path = el.getAttribute('comment_id');
|
||||
if (!path) {
|
||||
path = decodeURI(window.location.pathname);
|
||||
}
|
||||
Waline.init(Object.assign(<%- JSON.stringify(theme.comments.waline) %>, {
|
||||
el: '#waline_container',
|
||||
path: path,
|
||||
}));
|
||||
});
|
||||
}
|
||||
window.addEventListener('DOMContentLoaded', (event) => {
|
||||
console.log('DOM fully loaded and parsed');
|
||||
load_comment();
|
||||
});
|
||||
|
||||
</script>
|
Loading…
Reference in New Issue