Skip to content

Commit

Permalink
fix: 修复waline v3的引入问题 (#926)
Browse files Browse the repository at this point in the history
  • Loading branch information
zryyyy authored Sep 26, 2024
1 parent faae66b commit c4535bb
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions layout/_plugins/comments/waline/script.ejs
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
<script>
volantis.layoutHelper("comments",`<div id="waline"><i class="fa-solid fa-cog fa-spin fa-fw fa-2x"></i></div>`)
<script type="module">
import { init } from '<%- theme.cdn.waline_js %>';
volantis.layoutHelper("comments", `<div id="waline"><i class="fa-solid fa-cog fa-spin fa-fw fa-2x"></i></div>`)
function p_waline() {
if(!document.querySelector("#waline"))return;
if (!document.querySelector("#waline")) return;
let locale = {};
let path = pdata.commentPath;
let pagePlaceholder = pdata.commentPlaceholder || "<%= theme.comments.waline.placeholder %>";
if (path.length == 0) {
let defaultPath = '<%= theme.comments.waline.path %>';
path = defaultPath || decodeURI(window.location.pathname);
}
if(pagePlaceholder.length != 0) {
if (pagePlaceholder.length != 0) {
locale.placeholder = pagePlaceholder;
}
try {
Waline.init(Object.assign(Object.assign(<%- JSON.stringify(theme.comments.waline) %>, {
init(Object.assign(Object.assign(<%- JSON.stringify(theme.comments.waline) %>, {
el: '#waline',
path: path,
// https://github.com/volantis-x/hexo-theme-volantis/issues/713
Expand All @@ -24,38 +27,38 @@
let headers = new Headers();
headers.set('Accept', 'application/json');
<% if(!!theme.comments.waline.imageUploader?.token) { %>
headers.set('<%= theme.comments.waline.imageUploader?.tokenName %>', '<%= theme.comments.waline.imageUploader?.token %>')
headers.set('<%= theme.comments.waline.imageUploader?.tokenName %>', '<%= theme.comments.waline.imageUploader?.token %>');
<% } %>
let formData = new FormData();
formData.append('<%= theme.comments.waline.imageUploader?.fileName %>', file);
return fetch('<%= theme.comments.waline.imageUploader?.api %>',{
return fetch('<%= theme.comments.waline.imageUploader?.api %>', {
method: 'POST',
body: formData,
headers: headers
}).then((resp) => resp.json())
.then((resp) => resp.<%= theme.comments.waline.imageUploader?.resp %>)
}).then((resp) => resp.json())
.then((resp) => resp.<%= theme.comments.waline.imageUploader?.resp %>);
},
<% } %>
locale,
}),pdata.commentConfig));
}), pdata.commentConfig));
} catch (error) {
alert(`Waline ${error}`)
alert(`Waline ${error}`);
}
fancybox_waline()
fancybox_waline();
}
function fancybox_waline() {
if(typeof VolantisFancyBox === "undefined") {
if (typeof VolantisFancyBox === "undefined") {
const checkFancyBox = setInterval(() => {
if(typeof VolantisFancyBox === "undefined") return;
if (typeof VolantisFancyBox === "undefined") return;
clearInterval(checkFancyBox);
VolantisFancyBox.bind('#waline .wl-content img:not(.wl-emoji)');
})
});
} else {
VolantisFancyBox.bind('#waline .wl-content img:not(.wl-emoji)');
}
}
volantis.css('<%= theme.cdn.waline_css %>')
volantis.js('<%- theme.cdn.waline_js %>').then(p_waline)
</script>
volantis.css('<%= theme.cdn.waline_css %>');
volantis.js('<%- theme.cdn.waline_js %>').then(p_waline);
</script>

0 comments on commit c4535bb

Please sign in to comment.