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

36 lines
1.2 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 twikoo_cdn_url = `//cdn.jsdelivr.net/npm/twikoo@${tk_version}/dist/twikoo.all.min.js`
%>
<% 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' : '' %>>
2021-01-15 16:18:02 +08:00
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 %>') {
2021-01-15 16:18:02 +08:00
const loadTwikooTimeout = setTimeout(() => {
loadTwikoo();
clearTimeout(loadTwikooTimeout);
}, 1000);
} else {
window.addEventListener('DOMContentLoaded', loadTwikoo);
}
</script>
</div>
<% } %>