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

41 lines
1.7 KiB
Plaintext
Raw Normal View History

2020-10-29 15:42:58 +08:00
<% if(
theme.comment.gitalk.enable
&& theme.comment.gitalk.client_id
&& theme.comment.gitalk.client_secret
&& theme.comment.gitalk.github_id
&& theme.comment.gitalk.repository
) { %>
<div id="gitalk-container"></div>
<script <%= theme.pjax.enable === true ? 'data-pjax' : '' %>
src="//cdn.jsdelivr.net/npm/gitalk/dist/gitalk.min.js"></script>
<script <%= theme.pjax.enable === true ? 'data-pjax' : '' %>>
function loadGitalk() {
let __gitalk__pathname = decodeURI(location.pathname);
const __gitalk__pathnameLength = __gitalk__pathname.length;
const __gitalk__pathnameMaxLength = 50;
if (__gitalk__pathnameLength > __gitalk__pathnameMaxLength) {
__gitalk__pathname = __gitalk__pathname.substring(0, __gitalk__pathnameMaxLength - 3) + '...';
}
Gitalk && new Gitalk({
clientID: '<%= theme.comment.gitalk.client_id %>',
clientSecret: '<%= theme.comment.gitalk.client_secret %>',
repo: '<%= theme.comment.gitalk.repository %>',
owner: '<%= theme.comment.gitalk.github_id %>',
admin: ['<%= theme.comment.gitalk.github_id %>'],
id: __gitalk__pathname,
language: '<%= config.language %>'
}).render('gitalk-container');
}
if ('<%= theme.pjax.enable %>') {
const loadGitalkTimeout = setTimeout(() => {
loadGitalk();
clearTimeout(loadGitalkTimeout);
}, 1000);
} else {
window.addEventListener('DOMContentLoaded', loadGitalk);
2020-10-29 16:57:52 +08:00
}
2020-10-29 15:42:58 +08:00
</script>
<% } %>