2022-10-20 23:08:07 +08:00
|
|
|
<%
|
2022-10-21 00:08:49 +08:00
|
|
|
const { enable: pjax_enable } = theme?.pjax
|
2022-10-20 23:08:07 +08:00
|
|
|
const {
|
|
|
|
client_id,
|
2022-10-16 00:44:40 +08:00
|
|
|
client_secret,
|
|
|
|
repository,
|
|
|
|
github_id,
|
|
|
|
github_admins
|
2022-10-20 23:08:07 +08:00
|
|
|
} = theme.comment?.gitalk
|
|
|
|
let cdn_css = '//cdn.jsdelivr.net/npm/gitalk/dist/gitalk.css'
|
|
|
|
let cdn_js = '//cdn.jsdelivr.net/npm/gitalk/dist/gitalk.min.js'
|
|
|
|
const { enable: t_cdn_enable, provider: t_cdn_provider } = theme?.cdn
|
|
|
|
if (t_cdn_enable === true) {
|
|
|
|
switch (t_cdn_provider) {
|
|
|
|
case 'jsdelivr':
|
|
|
|
cdn_css = '//cdn.jsdelivr.net/npm/gitalk/dist/gitalk.css'
|
|
|
|
cdn_js = '//cdn.jsdelivr.net/npm/gitalk/dist/gitalk.min.js'
|
|
|
|
break
|
|
|
|
|
|
|
|
case 'unpkg':
|
|
|
|
cdn_css = '//unpkg.com/gitalk/dist/gitalk.css'
|
|
|
|
cdn_js = '//unpkg.com/gitalk/dist/gitalk.min.js'
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2022-10-16 00:44:40 +08:00
|
|
|
%>
|
2022-10-21 00:08:49 +08:00
|
|
|
<% if(client_id && client_secret && github_id && repository) { %>
|
2022-10-16 00:44:40 +08:00
|
|
|
<div class="gitalk-comment-container">
|
|
|
|
<div id="gitalk-container"></div>
|
2022-10-20 23:08:07 +08:00
|
|
|
<link rel="stylesheet" href="<%= cdn_css %>">
|
2022-10-21 00:08:49 +08:00
|
|
|
<script <%= pjax_enable === true ? 'data-pjax' : '' %> src="<%= cdn_js %>"></script>
|
|
|
|
<script <%= pjax_enable === true ? 'data-pjax' : '' %>>
|
2022-10-16 00:44:40 +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) + '...';
|
|
|
|
}
|
2020-12-30 18:11:46 +08:00
|
|
|
|
2022-10-16 00:44:40 +08:00
|
|
|
try {
|
|
|
|
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');
|
|
|
|
} catch (e) {
|
|
|
|
window.Gitalk = null;
|
|
|
|
}
|
|
|
|
}
|
2021-01-11 00:21:26 +08:00
|
|
|
|
2022-10-21 00:08:49 +08:00
|
|
|
if ('<%= pjax_enable %>' === 'true') {
|
2022-10-16 00:44:40 +08:00
|
|
|
const loadGitalkTimeout = setTimeout(() => {
|
|
|
|
loadGitalk();
|
|
|
|
clearTimeout(loadGitalkTimeout);
|
|
|
|
}, 1000);
|
|
|
|
} else {
|
|
|
|
window.addEventListener('DOMContentLoaded', loadGitalk);
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</div>
|
2020-10-29 15:42:58 +08:00
|
|
|
<% } %>
|