hexo-theme-keep/layout/_partial/comment/twikoo.ejs

48 lines
1.5 KiB
Plaintext

<%
const { enable: pjax_enable } = theme?.pjax
let {
env_id: tk_env_id,
region: tk_region,
version: tk_version
} = theme.comment?.twikoo
if (!tk_version) { tk_version = '1.6.7' }
const { enable: t_cdn_enable, provider: t_cdn_provider } = theme?.cdn
let twikoo_cdn_url = `//cdn.jsdelivr.net/npm/twikoo@${tk_version}/dist/twikoo.all.min.js`
if (t_cdn_enable === true) {
switch (t_cdn_provider) {
case 'jsdelivr':
twikoo_cdn_url = `//cdn.jsdelivr.net/npm/twikoo@${tk_version}/dist/twikoo.all.min.js`
break
case 'unpkg':
twikoo_cdn_url = `//unpkg.com/twikoo@${tk_version}/dist/twikoo.all.min.js`
break
}
}
%>
<% if(tk_env_id) { %>
<div class="twikoo-container">
<script <%= pjax_enable === true ? 'data-pjax' : '' %> src="<%= twikoo_cdn_url %>"></script>
<div id="twikoo-comment"></div>
<script <%= pjax_enable === true ? 'data-pjax' : '' %>>
function loadTwikoo() {
twikoo.init({
el: '#twikoo-comment',
envId: '<%= tk_env_id %>',
region: '<%= tk_region %>',
lang: '<%= config.language %>' || 'zh-CN'
});
}
if ('<%= pjax_enable %>' === 'true') {
const loadTwikooTimeout = setTimeout(() => {
loadTwikoo();
clearTimeout(loadTwikooTimeout);
}, 1000);
} else {
window.addEventListener('DOMContentLoaded', loadTwikoo);
}
</script>
</div>
<% } %>