style(gitalk): gitalk.ejs code optimization
This commit is contained in:
parent
f316f865cd
commit
2d80c45ec5
|
@ -1,46 +1,49 @@
|
||||||
|
<% const { client_id, client_secret, repository, github_id, github_admins } = theme.comment.gitalk %>
|
||||||
|
|
||||||
<% if(
|
<% if(
|
||||||
theme.comment.use === 'gitalk'
|
theme.comment.use === 'gitalk'
|
||||||
&& theme.comment.gitalk.client_id
|
&& client_id
|
||||||
&& theme.comment.gitalk.client_secret
|
&& client_secret
|
||||||
&& theme.comment.gitalk.github_id
|
&& github_id
|
||||||
&& theme.comment.gitalk.repository
|
&& repository
|
||||||
) { %>
|
) { %>
|
||||||
<div id="gitalk-container"></div>
|
<div id="gitalk-container"></div>
|
||||||
<script <%= theme.pjax.enable === true ? 'data-pjax' : '' %>
|
<script <%= theme.pjax.enable === true ? 'data-pjax' : '' %>
|
||||||
src="//cdn.jsdelivr.net/npm/gitalk/dist/gitalk.min.js"></script>
|
src="//cdn.jsdelivr.net/npm/gitalk/dist/gitalk.min.js"></script>
|
||||||
<script <%= theme.pjax.enable === true ? 'data-pjax' : '' %>>
|
<script <%= theme.pjax.enable === true ? 'data-pjax' : '' %>>
|
||||||
|
|
||||||
function loadGitalk() {
|
function loadGitalk() {
|
||||||
let __gitalk__pathname = decodeURI(location.pathname);
|
let __gitalk__pathname = decodeURI(location.pathname);
|
||||||
const __gitalk__pathnameLength = __gitalk__pathname.length;
|
const __gitalk__pathnameLength = __gitalk__pathname.length;
|
||||||
const __gitalk__pathnameMaxLength = 50;
|
const __gitalk__pathnameMaxLength = 50;
|
||||||
if (__gitalk__pathnameLength > __gitalk__pathnameMaxLength) {
|
if (__gitalk__pathnameLength > __gitalk__pathnameMaxLength) {
|
||||||
__gitalk__pathname = __gitalk__pathname.substring(0, __gitalk__pathnameMaxLength - 3) + '...';
|
__gitalk__pathname = __gitalk__pathname.substring(0, __gitalk__pathnameMaxLength - 3) + '...';
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
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: <% if (theme.comment.gitalk.github_admins) { %><%= theme.comment.gitalk.github_admins %><% } else { %>['<%= theme.comment.gitalk.github_id %>']<% } %>,
|
|
||||||
id: __gitalk__pathname,
|
|
||||||
language: '<%= config.language %>'
|
|
||||||
}).render('gitalk-container');
|
|
||||||
|
|
||||||
} catch (e) {
|
|
||||||
window.Gitalk = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('<%= theme.pjax.enable %>') {
|
try {
|
||||||
const loadGitalkTimeout = setTimeout(() => {
|
|
||||||
loadGitalk();
|
Gitalk && new Gitalk({
|
||||||
clearTimeout(loadGitalkTimeout);
|
clientID: '<%= client_id %>',
|
||||||
}, 1000);
|
clientSecret: '<%= client_secret %>',
|
||||||
} else {
|
repo: '<%= repository %>',
|
||||||
window.addEventListener('DOMContentLoaded', loadGitalk);
|
owner: '<%= github_id %>',
|
||||||
|
admin: '<%= github_admins || [github_id] %>',
|
||||||
|
id: __gitalk__pathname,
|
||||||
|
language: '<%= config.language %>'
|
||||||
|
}).render('gitalk-container');
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
window.Gitalk = null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('<%= theme.pjax.enable %>') {
|
||||||
|
const loadGitalkTimeout = setTimeout(() => {
|
||||||
|
loadGitalk();
|
||||||
|
clearTimeout(loadGitalkTimeout);
|
||||||
|
}, 1000);
|
||||||
|
} else {
|
||||||
|
window.addEventListener('DOMContentLoaded', loadGitalk);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
Loading…
Reference in New Issue