2022-09-23 14:23:26 +08:00
|
|
|
<% const { client_id, client_secret, repository, github_id, github_admins } = theme.comment.gitalk %>
|
|
|
|
|
2020-10-29 15:42:58 +08:00
|
|
|
<% if(
|
2021-01-28 17:44:01 +08:00
|
|
|
theme.comment.use === 'gitalk'
|
2022-09-23 14:23:26 +08:00
|
|
|
&& client_id
|
|
|
|
&& client_secret
|
|
|
|
&& github_id
|
|
|
|
&& repository
|
2020-10-29 15:42:58 +08:00
|
|
|
) { %>
|
2021-01-06 18:48:30 +08:00
|
|
|
<div id="gitalk-container"></div>
|
2020-12-30 18:11:46 +08:00
|
|
|
<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' : '' %>>
|
|
|
|
|
2022-09-23 14:23:26 +08:00
|
|
|
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) + '...';
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2021-01-11 00:21:26 +08:00
|
|
|
|
2022-09-23 14:23:26 +08:00
|
|
|
Gitalk && new Gitalk({
|
|
|
|
clientID: '<%= client_id %>',
|
|
|
|
clientSecret: '<%= client_secret %>',
|
|
|
|
repo: '<%= repository %>',
|
|
|
|
owner: '<%= github_id %>',
|
|
|
|
admin: '<%= github_admins || [github_id] %>',
|
|
|
|
id: __gitalk__pathname,
|
|
|
|
language: '<%= config.language %>'
|
|
|
|
}).render('gitalk-container');
|
2021-01-11 00:21:26 +08:00
|
|
|
|
2022-09-23 14:23:26 +08:00
|
|
|
} catch (e) {
|
|
|
|
window.Gitalk = null;
|
2020-12-30 18:11:46 +08:00
|
|
|
}
|
2022-09-23 14:23:26 +08:00
|
|
|
}
|
2020-12-30 18:11:46 +08:00
|
|
|
|
2022-09-23 14:23:26 +08:00
|
|
|
if ('<%= theme.pjax.enable %>') {
|
|
|
|
const loadGitalkTimeout = setTimeout(() => {
|
|
|
|
loadGitalk();
|
|
|
|
clearTimeout(loadGitalkTimeout);
|
|
|
|
}, 1000);
|
|
|
|
} else {
|
|
|
|
window.addEventListener('DOMContentLoaded', loadGitalk);
|
|
|
|
}
|
2020-10-29 15:42:58 +08:00
|
|
|
</script>
|
|
|
|
<% } %>
|