hexo-theme-stellar/layout/_partial/comments/waline/script.ejs

37 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

2024-02-23 15:24:37 +08:00
<script type="module">
2024-05-31 20:32:04 +08:00
import { init } from '<%- theme.comments.waline.js %>';
2024-02-23 15:24:37 +08:00
2024-05-31 20:32:04 +08:00
const el = document.getElementById('waline_container');
util.viewportLazyload(el, load_waline, <%= theme.comments.lazyload ?? false %>);
function load_waline(){
if (!el) return;
2024-02-23 15:24:37 +08:00
2024-02-12 23:07:56 +08:00
utils.css('<%- theme.comments.waline.css %>');
2024-02-23 15:24:37 +08:00
utils.css('<%- theme.comments.waline.meta_css %>');
const path = el.getAttribute('comment_id') ?? decodeURI(window.location.pathname);
2024-02-23 15:24:37 +08:00
const waline = init(Object.assign(<%- JSON.stringify(theme.comments.waline) %>, {
el: '#waline_container',
path: path,
<% if(!!theme.comments.waline.imageUploader?.api){ %>
imageUploader: function(file) {
2024-05-31 20:32:04 +08:00
const headers = new Headers();
2024-02-23 15:24:37 +08:00
headers.set('Accept', 'application/json');
<% if(!!theme.comments.waline.imageUploader?.token) { %>
headers.set('<%= theme.comments.waline.imageUploader?.tokenName %>', '<%= theme.comments.waline.imageUploader?.token %>')
<% } %>
2024-05-31 20:32:04 +08:00
const formData = new FormData();
2024-02-23 15:24:37 +08:00
formData.append('<%= theme.comments.waline.imageUploader?.fileName %>', file);
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 %>)
},
<% } %>
}));
2022-05-18 20:25:53 +08:00
}
</script>