Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Commit

Permalink
feat(comment): add gitalk support
Browse files Browse the repository at this point in the history
  • Loading branch information
ppoffice committed Jan 8, 2019
1 parent 5ab7538 commit 131b7e9
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
8 changes: 8 additions & 0 deletions _config.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ comment:
avatar: identicon # (''/mm/identicon/monsterid/wavatar/retro/hide), more to see https://valine.js.org/avatar/
avatar_cdn: https://gravatar.loli.net/avatar/ # avatar CDN address, default gravatar.loli.net
pageSize: 10 # comments of one page
gitalk:
on: # enter true to enable gitalk
owner: # GitHub user name
repo: # GitHub repository name
client_id: # OAuth application client id
client_secret: # OAuth application client secret
admin: # GitHub repo owner and collaborators who can initialize github issues
# Can either be a string or an array.

# Share
share: default # options: jiathis, bdshare, addtoany, default
Expand Down
17 changes: 17 additions & 0 deletions layout/comment/gitalk.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<% if (typeof(script) !== 'undefined' && script) { %>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
<script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>
<script>
var gitalk = new Gitalk({
clientID: '<%= theme.comment.gitalk.client_id %>',
clientSecret: '<%= theme.comment.gitalk.client_secret %>',
id: '<%= md5(page.path) %>',
repo: '<%= theme.comment.gitalk.repo %>',
owner: '<%= theme.comment.gitalk.owner %>',
admin: <%- JSON.stringify(theme.comment.gitalk.admin)%>
})
gitalk.render('comment-container')
</script>
<% } else { %>
<div id="comment-container"></div>
<% } %>
4 changes: 3 additions & 1 deletion layout/comment/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
<%- partial('comment/livere') %>
<% } else if (theme.comment.facebook) { %>
<%- partial('comment/facebook') %>
<% } else if (typeof(theme.comment.isso) === 'string'
<% } else if (typeof(theme.comment.isso) === 'string'
|| theme.comment.isso && theme.comment.isso.on) { %>
<%- partial('comment/isso') %>
<% } else if (theme.comment.changyan.on) { %>
<%- partial('comment/changyan') %>
<% } else if (theme.comment.valine.on) { %>
<%- partial('comment/valine') %>
<% } else if (theme.comment.gitalk.on) { %>
<%- partial('comment/gitalk') %>
<% } %>
</section>
<% } %>
4 changes: 3 additions & 1 deletion layout/comment/scripts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
<%- partial('comment/livere', { script: true }) %>
<% } else if (theme.comment.facebook) { %>
<%- partial('comment/facebook', { script: true }) %>
<% } else if (typeof(theme.comment.isso) === 'string'
<% } else if (typeof(theme.comment.isso) === 'string'
|| theme.comment.isso && theme.comment.isso.on) { %>
<%- partial('comment/isso', { script: true }) %>
<% } else if (theme.comment.changyan.on) { %>
<%- partial('comment/changyan', { script: true }) %>
<% } else if (theme.comment.valine.on) { %>
<%- partial('comment/valine', { script: true }) %>
<% } else if (theme.comment.gitalk.on) { %>
<%- partial('comment/gitalk', { script: true }) %>
<% } %>
11 changes: 11 additions & 0 deletions scripts/md5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* MD5 Hash Helper
* @description Calculate the MD5 hash value of a string
* @example
* <%- md5(data) %>
*/
const crypto = require('crypto');

hexo.extend.helper.register('md5', function (data) {
return crypto.createHash('md5').update(data).digest("hex");
});

1 comment on commit 131b7e9

@ppoffice
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.