waline 3.x (#396)

This commit is contained in:
panoshu 2024-02-23 15:24:37 +08:00 committed by GitHub
parent dca305c5c3
commit 575fc5fef0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 31 deletions

View File

@ -204,8 +204,9 @@ comments:
# Waline # Waline
# https://waline.js.org/ # https://waline.js.org/
waline: waline:
js: https://unpkg.com/@waline/client@2.14.1/dist/waline.js js: https://gcore.jsdelivr.net/npm/@waline/client@3.1.2/dist/waline.js
css: https://unpkg.com/@waline/client@2.14.1/dist/waline.css css: https://gcore.jsdelivr.net/npm/@waline/client@3.1.2/dist/waline.css
meta_css: https://gcore.jsdelivr.net/npm/@waline/client@3.1.2/dist/waline-meta.css
# Waline server address url, you should set this to your own link # Waline server address url, you should set this to your own link
serverURL: serverURL:
# If false, comment count will only be displayed in post page, not in home page # If false, comment count will only be displayed in post page, not in home page

View File

@ -1,35 +1,40 @@
<script> <script type="module">
import { init } from '<%- theme.comments.waline.js %>'
function load_comment(){ function load_comment(){
if(!document.getElementById("waline_container"))return; if(!document.getElementById("waline_container"))return;
utils.css('<%- theme.comments.waline.css %>'); utils.css('<%- theme.comments.waline.css %>');
utils.js('<%- theme.comments.waline.js %>', {defer:true}).then(function () { utils.css('<%- theme.comments.waline.meta_css %>');
const el = document.getElementById("waline_container");
var path = el.getAttribute('comment_id'); const el = document.getElementById("waline_container");
if (!path) { var path = el.getAttribute('comment_id');
path = decodeURI(window.location.pathname); if (!path) {
} path = decodeURI(window.location.pathname);
Waline.init(Object.assign(<%- JSON.stringify(theme.comments.waline) %>, { }
el: '#waline_container',
path: path, const waline = init(Object.assign(<%- JSON.stringify(theme.comments.waline) %>, {
<% if(!!theme.comments.waline.imageUploader?.api){ %> el: '#waline_container',
imageUploader: function(file) { path: path,
let headers = new Headers(); <% if(!!theme.comments.waline.imageUploader?.api){ %>
headers.set('Accept', 'application/json'); imageUploader: function(file) {
<% if(!!theme.comments.waline.imageUploader?.token) { %> let headers = new Headers();
headers.set('<%= theme.comments.waline.imageUploader?.tokenName %>', '<%= theme.comments.waline.imageUploader?.token %>') headers.set('Accept', 'application/json');
<% } %> <% if(!!theme.comments.waline.imageUploader?.token) { %>
let formData = new FormData(); headers.set('<%= theme.comments.waline.imageUploader?.tokenName %>', '<%= theme.comments.waline.imageUploader?.token %>')
formData.append('<%= theme.comments.waline.imageUploader?.fileName %>', file); <% } %>
return fetch('<%= theme.comments.waline.imageUploader?.api %>',{ let formData = new FormData();
method: 'POST', formData.append('<%= theme.comments.waline.imageUploader?.fileName %>', file);
body: formData, return fetch('<%= theme.comments.waline.imageUploader?.api %>',{
headers: headers method: 'POST',
}).then((resp) => resp.json()) body: formData,
.then((resp) => resp.<%= theme.comments.waline.imageUploader?.resp %>) headers: headers
}, }).then((resp) => resp.json())
<% } %> .then((resp) => resp.<%= theme.comments.waline.imageUploader?.resp %>)
})); },
}); <% } %>
}));
} }
window.addEventListener('DOMContentLoaded', (event) => { window.addEventListener('DOMContentLoaded', (event) => {
load_comment(); load_comment();