Skip to content

Commit c4535bb

Browse files
authored
fix: 修复waline v3的引入问题 (#926)
1 parent faae66b commit c4535bb

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed
+22-19
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
<script>
2-
volantis.layoutHelper("comments",`<div id="waline"><i class="fa-solid fa-cog fa-spin fa-fw fa-2x"></i></div>`)
3-
1+
<script type="module">
2+
import { init } from '<%- theme.cdn.waline_js %>';
3+
4+
volantis.layoutHelper("comments", `<div id="waline"><i class="fa-solid fa-cog fa-spin fa-fw fa-2x"></i></div>`)
5+
46
function p_waline() {
5-
if(!document.querySelector("#waline"))return;
7+
if (!document.querySelector("#waline")) return;
8+
69
let locale = {};
710
let path = pdata.commentPath;
811
let pagePlaceholder = pdata.commentPlaceholder || "<%= theme.comments.waline.placeholder %>";
912
if (path.length == 0) {
1013
let defaultPath = '<%= theme.comments.waline.path %>';
1114
path = defaultPath || decodeURI(window.location.pathname);
1215
}
13-
if(pagePlaceholder.length != 0) {
16+
if (pagePlaceholder.length != 0) {
1417
locale.placeholder = pagePlaceholder;
1518
}
1619
1720
try {
18-
Waline.init(Object.assign(Object.assign(<%- JSON.stringify(theme.comments.waline) %>, {
21+
init(Object.assign(Object.assign(<%- JSON.stringify(theme.comments.waline) %>, {
1922
el: '#waline',
2023
path: path,
2124
// https://github.com/volantis-x/hexo-theme-volantis/issues/713
@@ -24,38 +27,38 @@
2427
let headers = new Headers();
2528
headers.set('Accept', 'application/json');
2629
<% if(!!theme.comments.waline.imageUploader?.token) { %>
27-
headers.set('<%= theme.comments.waline.imageUploader?.tokenName %>', '<%= theme.comments.waline.imageUploader?.token %>')
30+
headers.set('<%= theme.comments.waline.imageUploader?.tokenName %>', '<%= theme.comments.waline.imageUploader?.token %>');
2831
<% } %>
2932
let formData = new FormData();
3033
formData.append('<%= theme.comments.waline.imageUploader?.fileName %>', file);
31-
return fetch('<%= theme.comments.waline.imageUploader?.api %>',{
34+
return fetch('<%= theme.comments.waline.imageUploader?.api %>', {
3235
method: 'POST',
3336
body: formData,
3437
headers: headers
35-
}).then((resp) => resp.json())
36-
.then((resp) => resp.<%= theme.comments.waline.imageUploader?.resp %>)
38+
}).then((resp) => resp.json())
39+
.then((resp) => resp.<%= theme.comments.waline.imageUploader?.resp %>);
3740
},
3841
<% } %>
3942
locale,
40-
}),pdata.commentConfig));
43+
}), pdata.commentConfig));
4144
} catch (error) {
42-
alert(`Waline ${error}`)
45+
alert(`Waline ${error}`);
4346
}
44-
fancybox_waline()
47+
fancybox_waline();
4548
}
4649
4750
function fancybox_waline() {
48-
if(typeof VolantisFancyBox === "undefined") {
51+
if (typeof VolantisFancyBox === "undefined") {
4952
const checkFancyBox = setInterval(() => {
50-
if(typeof VolantisFancyBox === "undefined") return;
53+
if (typeof VolantisFancyBox === "undefined") return;
5154
clearInterval(checkFancyBox);
5255
VolantisFancyBox.bind('#waline .wl-content img:not(.wl-emoji)');
53-
})
56+
});
5457
} else {
5558
VolantisFancyBox.bind('#waline .wl-content img:not(.wl-emoji)');
5659
}
5760
}
5861
59-
volantis.css('<%= theme.cdn.waline_css %>')
60-
volantis.js('<%- theme.cdn.waline_js %>').then(p_waline)
61-
</script>
62+
volantis.css('<%= theme.cdn.waline_css %>');
63+
volantis.js('<%- theme.cdn.waline_js %>').then(p_waline);
64+
</script>

0 commit comments

Comments
 (0)