hexo-theme-stellar/layout/_partial/plugins/comments/utterances/script.ejs

41 lines
1.4 KiB
Plaintext

<%
if (page.utterances == undefined) {
page.utterances = theme.comments.utterances;
} else {
for (let key of Object.keys(theme.comments.utterances)) {
if (page.utterances[key] == undefined) {
page.utterances[key] = theme.comments.utterances[key];
}
}
}
%>
<script>
function pjax_utterances(){
if(!document.getElementById("utterances"))return;
setTimeout(function() {
var checkUtterances = setInterval(function () {
var HEAD = document.getElementById("utterances");
if (!HEAD) return
clearInterval(checkUtterances)
try {
HEAD.innerHTML="";
} catch (error) {}
var script = document.createElement('script');
script.setAttribute('src','https://utteranc.es/client.js');
script.setAttribute('repo','<%- page.utterances.repo %>');
let issuenumber = '<%- page.utterances['issue-number'] || page.comment_id %>';
if (issuenumber) {
script.setAttribute('issue-term', issuenumber);
} else {
script.setAttribute('issue-term', '<%- page.utterances['issue-term'] %>');
}
script.setAttribute('theme', '<%- page.dark ? page.utterances.theme.dark : page.utterances.theme.light %>' );
script.setAttribute('label','<%- page.utterances.label %>');
script.setAttribute('crossorigin','<%- page.utterances.crossorigin %>');
HEAD.appendChild(script);
}, 200)
});
}
pjax_utterances();
</script>