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

52 lines
1.6 KiB
Plaintext
Raw Normal View History

<%
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(theme.comment.use === 'twikoo' && tk_env_id) { %>
2021-01-15 16:18:02 +08:00
<div class="twikoo-container">
<script <%= pjax_enable === true ? 'data-pjax' : '' %>
src="<%= twikoo_cdn_url %>"
2021-01-15 16:18:02 +08:00
></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'
});
}
2021-01-15 16:18:02 +08:00
if ('<%= pjax_enable %>' === 'true') {
const loadTwikooTimeout = setTimeout(() => {
loadTwikoo();
clearTimeout(loadTwikooTimeout);
}, 1000);
} else {
window.addEventListener('DOMContentLoaded', loadTwikoo);
}
2021-01-15 16:18:02 +08:00
</script>
</div>
<% } %>