chore(comment): improve gitalk comment integration
This commit is contained in:
parent
e062bf4fc0
commit
6199abcafc
|
@ -9,9 +9,11 @@
|
||||||
* <%- tag_count() %>
|
* <%- tag_count() %>
|
||||||
* <%- duration() %>
|
* <%- duration() %>
|
||||||
* <%- word_count(content) %>
|
* <%- word_count(content) %>
|
||||||
|
* <%- md5(data) %>
|
||||||
*/
|
*/
|
||||||
const URL = require('url').URL;
|
const URL = require('url').URL;
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
|
const crypto = require('crypto');
|
||||||
|
|
||||||
module.exports = function (hexo) {
|
module.exports = function (hexo) {
|
||||||
hexo.extend.helper.register('is_same_link', function (a, b) {
|
hexo.extend.helper.register('is_same_link', function (a, b) {
|
||||||
|
@ -57,4 +59,8 @@ module.exports = function (hexo) {
|
||||||
content = content.trim();
|
content = content.trim();
|
||||||
return content ? (content.match(/[\u00ff-\uffff]|[a-zA-Z]+/g) || []).length : 0;
|
return content ? (content.match(/[\u00ff-\uffff]|[a-zA-Z]+/g) || []).length : 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
hexo.extend.helper.register('md5', function (data) {
|
||||||
|
return crypto.createHash('md5').update(data).digest("hex")
|
||||||
|
});
|
||||||
}
|
}
|
|
@ -24,30 +24,40 @@ const DisqusSpec = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const GitmentSpec = {
|
const GitmentGitalkSpec = {
|
||||||
owner: {
|
owner: {
|
||||||
[type]: 'string',
|
[type]: 'string',
|
||||||
[doc]: 'Your GitHub ID',
|
[doc]: 'GitHub user ID',
|
||||||
[required]: true,
|
[required]: true,
|
||||||
[requires]: comment => comment.type === 'gitment'
|
[requires]: comment => comment.type === 'gitment' || comment.type === 'gitalk'
|
||||||
},
|
},
|
||||||
repo: {
|
repo: {
|
||||||
[type]: 'string',
|
[type]: 'string',
|
||||||
[doc]: 'The repo to store comments',
|
[doc]: 'GitHub repo name to store comments',
|
||||||
[required]: true,
|
[required]: true,
|
||||||
[requires]: comment => comment.type === 'gitment'
|
[requires]: comment => comment.type === 'gitment' || comment.type === 'gitalk'
|
||||||
},
|
},
|
||||||
client_id: {
|
client_id: {
|
||||||
[type]: 'string',
|
[type]: 'string',
|
||||||
[doc]: 'Your client ID',
|
[doc]: 'GitHub application client ID',
|
||||||
[required]: true,
|
[required]: true,
|
||||||
[requires]: comment => comment.type === 'gitment'
|
[requires]: comment => comment.type === 'gitment' || comment.type === 'gitalk'
|
||||||
},
|
},
|
||||||
client_secret: {
|
client_secret: {
|
||||||
[type]: 'string',
|
[type]: 'string',
|
||||||
[doc]: 'Your client secret',
|
[doc]: 'GitHub application client secret',
|
||||||
[required]: true,
|
[required]: true,
|
||||||
[requires]: comment => comment.type === 'gitment'
|
[requires]: comment => comment.type === 'gitment' || comment.type === 'gitalk'
|
||||||
|
},
|
||||||
|
admin: {
|
||||||
|
[type]: ['string', 'array'],
|
||||||
|
[doc]: 'GitHub repo owner and collaborators who can can initialize github issues',
|
||||||
|
[required]: true,
|
||||||
|
[requires]: comment => comment.type === 'gitalk',
|
||||||
|
'*': {
|
||||||
|
[type]: 'string',
|
||||||
|
[required]: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -112,7 +122,7 @@ module.exports = {
|
||||||
},
|
},
|
||||||
...ChangYanSpec,
|
...ChangYanSpec,
|
||||||
...DisqusSpec,
|
...DisqusSpec,
|
||||||
...GitmentSpec,
|
...GitmentGitalkSpec,
|
||||||
...IssoSpec,
|
...IssoSpec,
|
||||||
...LiveReSpec,
|
...LiveReSpec,
|
||||||
...ValineSpec
|
...ValineSpec
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
<% if (!has_config('comment.owner') || !has_config('comment.admin') || !has_config('comment.repo') || !has_config('comment.client_id') ||
|
||||||
|
!has_config('comment.client_secret')) { %>
|
||||||
|
<div class="notification is-danger">
|
||||||
|
You forgot to set the <code>owner</code>, <code>admin</code>, <code>repo</code>, <code>client_id</code>, or <code>client_secret</code> for Gittalk.
|
||||||
|
Please set it in <code>_config.yml</code>.
|
||||||
|
</div>
|
||||||
|
<% } else { %>
|
||||||
|
<div id="comment-container"></div>
|
||||||
|
<%- _css(cdn('gitalk', '1.4.1', 'dist/gitalk.css')) %>
|
||||||
|
<%- _js(cdn('gitalk', '1.4.1', 'dist/gitalk.min.js')) %>
|
||||||
|
<script>
|
||||||
|
var gitalk = new Gitalk({
|
||||||
|
clientID: '<%= get_config('comment.client_id') %>',
|
||||||
|
clientSecret: '<%= get_config('comment.client_secret') %>',
|
||||||
|
id: '<%= md5(page.path) %>',
|
||||||
|
repo: '<%= get_config('comment.repo') %>',
|
||||||
|
owner: '<%= get_config('comment.owner') %>',
|
||||||
|
admin: <%- JSON.stringify(get_config('comment.admin'))%>
|
||||||
|
})
|
||||||
|
gitalk.render('comment-container')
|
||||||
|
</script>
|
||||||
|
<% } %>
|
|
@ -1,23 +0,0 @@
|
||||||
<% if (!has_config('comment.owner') || !has_config('comment.admin') || !has_config('comment.repo') || !has_config('comment.client_id') ||
|
|
||||||
!has_config('comment.client_secret')) { %>
|
|
||||||
<div class="notification is-danger">
|
|
||||||
You forgot to set the <code>owner</code>, <code>admin</code>, <code>repo</code>, <code>client_id</code>, or <code>client_secret</code> for Gittalk.
|
|
||||||
Please set it in <code>_config.yml</code>.
|
|
||||||
</div>
|
|
||||||
<% } else { %>
|
|
||||||
<div id="comment-container"></div>
|
|
||||||
<link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css">
|
|
||||||
<script src="https://unpkg.com/gitalk/dist/gitalk.min.js"></script>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/blueimp-md5@2.10.0/js/md5.min.js"></script>
|
|
||||||
<script>
|
|
||||||
var gitalk = new Gitalk({
|
|
||||||
clientID: '<%= get_config('comment.client_id') %>',
|
|
||||||
clientSecret: '<%= get_config('comment.client_secret') %>',
|
|
||||||
id: md5(decodeURI(location.pathname)),
|
|
||||||
repo: '<%= get_config('comment.repo') %>',
|
|
||||||
owner: '<%= get_config('comment.owner') %>',
|
|
||||||
admin: '<%= get_config('comment.admin') %>'
|
|
||||||
})
|
|
||||||
gitalk.render('comment-container')
|
|
||||||
</script>
|
|
||||||
<% } %>
|
|
|
@ -1,8 +1,10 @@
|
||||||
document.addEventListener('DOMContentLoaded', function () {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
$('figure.highlight').each(function () {
|
if (typeof(ClipboardJS) !== 'undefined') {
|
||||||
var id = 'code-' + Date.now() + (Math.random() * 1000 | 0);
|
$('figure.highlight').each(function () {
|
||||||
$(this).attr('id', id);
|
var id = 'code-' + Date.now() + (Math.random() * 1000 | 0);
|
||||||
$(this).prepend($(`<button class="button is-borderless is-radiusless is-small copy" data-clipboard-target="#${id} .code" title="Copy"><i class="fas fa-copy"></i></button>`));
|
$(this).attr('id', id);
|
||||||
});
|
$(this).prepend($(`<button class="button is-borderless is-radiusless is-small copy" data-clipboard-target="#${id} .code" title="Copy"><i class="fas fa-copy"></i></button>`));
|
||||||
new ClipboardJS('.highlight .copy');
|
});
|
||||||
|
new ClipboardJS('.highlight .copy');
|
||||||
|
}
|
||||||
});
|
});
|
Loading…
Reference in New Issue