[feat] add waline v3

This commit is contained in:
xaoxuu 2024-02-23 12:31:21 +08:00
parent 53fddd24be
commit dca305c5c3
5 changed files with 47 additions and 1 deletions

View File

@ -242,6 +242,10 @@ comments:
# token: # 图床验证 # token: # 图床验证
# resp: # 图片地址返回值的字段 # resp: # 图片地址返回值的字段
waline_v3:
# Waline server address url, you should set this to your own link
serverURL: https://waline.vercel.app
# Artalk # Artalk
# https://artalk.js.org/ # https://artalk.js.org/
artalk: artalk:

View File

@ -0,0 +1,23 @@
<%
function layoutDiv() {
var el = ''
el += '<div id="waline_container" class="waline_thread"'
const cfg = theme.comments['waline_v3']
var attrs = {}
if (page.comment_id) {
attrs['comment_id'] = page.comment_id
}
// 参数在这里进行传递
attrs.serverURL = cfg?.serverURL
for (let key of Object.keys(attrs)) {
if (attrs[key]) {
el += ' ' + key + '="' + attrs[key] + '"'
}
}
el += `>${icon('default:loading')}</div>`
return el
}
%>
<%- layoutDiv() %>

View File

@ -0,0 +1,17 @@
<script defer type="module">
import { init } from 'https://unpkg.com/@waline/client@v3/dist/waline.js';
window.addEventListener('DOMContentLoaded', (event) => {
utils.css('https://unpkg.com/@waline/client@v3/dist/waline.css');
const id = 'waline_container';
const el = document.getElementById(id);
var path = el.getAttribute('comment_id');
if (!path) {
path = decodeURI(window.location.pathname);
}
const waline = init({
el: `#${id}`,
path: path,
serverURL: el.getAttribute('serverURL'),
});
});
</script>

View File

@ -1,4 +1,4 @@
.cmt-body.waline .cmt-body
.wl-panel .wl-panel
margin: 0.5em 0 !important margin: 0.5em 0 !important
.wl-meta-head .wl-meta-head

View File

@ -28,5 +28,7 @@ if hexo-config('comments.service') == 'utterances'
@import 'comments/utterances' @import 'comments/utterances'
if hexo-config('comments.service') == 'waline' if hexo-config('comments.service') == 'waline'
@import 'comments/waline' @import 'comments/waline'
if hexo-config('comments.service') == 'waline_v3'
@import 'comments/waline'
if hexo-config('comments.service') == 'artalk' if hexo-config('comments.service') == 'artalk'
@import 'comments/artalk' @import 'comments/artalk'