Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复waline v3的引入问题 #926

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>