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

Commit 131b7e9

Browse files
author
ppoffice
committedJan 8, 2019
feat(comment): add gitalk support
1 parent 5ab7538 commit 131b7e9

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed
 

‎_config.yml.example

+8
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ comment:
7575
avatar: identicon # (''/mm/identicon/monsterid/wavatar/retro/hide), more to see https://valine.js.org/avatar/
7676
avatar_cdn: https://gravatar.loli.net/avatar/ # avatar CDN address, default gravatar.loli.net
7777
pageSize: 10 # comments of one page
78+
gitalk:
79+
on: # enter true to enable gitalk
80+
owner: # GitHub user name
81+
repo: # GitHub repository name
82+
client_id: # OAuth application client id
83+
client_secret: # OAuth application client secret
84+
admin: # GitHub repo owner and collaborators who can initialize github issues
85+
# Can either be a string or an array.
7886

7987
# Share
8088
share: default # options: jiathis, bdshare, addtoany, default

‎layout/comment/gitalk.ejs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<% if (typeof(script) !== 'undefined' && script) { %>
2+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
3+
<script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>
4+
<script>
5+
var gitalk = new Gitalk({
6+
clientID: '<%= theme.comment.gitalk.client_id %>',
7+
clientSecret: '<%= theme.comment.gitalk.client_secret %>',
8+
id: '<%= md5(page.path) %>',
9+
repo: '<%= theme.comment.gitalk.repo %>',
10+
owner: '<%= theme.comment.gitalk.owner %>',
11+
admin: <%- JSON.stringify(theme.comment.gitalk.admin)%>
12+
})
13+
gitalk.render('comment-container')
14+
</script>
15+
<% } else { %>
16+
<div id="comment-container"></div>
17+
<% } %>

‎layout/comment/index.ejs

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
<%- partial('comment/livere') %>
1111
<% } else if (theme.comment.facebook) { %>
1212
<%- partial('comment/facebook') %>
13-
<% } else if (typeof(theme.comment.isso) === 'string'
13+
<% } else if (typeof(theme.comment.isso) === 'string'
1414
|| theme.comment.isso && theme.comment.isso.on) { %>
1515
<%- partial('comment/isso') %>
1616
<% } else if (theme.comment.changyan.on) { %>
1717
<%- partial('comment/changyan') %>
1818
<% } else if (theme.comment.valine.on) { %>
1919
<%- partial('comment/valine') %>
20+
<% } else if (theme.comment.gitalk.on) { %>
21+
<%- partial('comment/gitalk') %>
2022
<% } %>
2123
</section>
2224
<% } %>

‎layout/comment/scripts.ejs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
<%- partial('comment/livere', { script: true }) %>
99
<% } else if (theme.comment.facebook) { %>
1010
<%- partial('comment/facebook', { script: true }) %>
11-
<% } else if (typeof(theme.comment.isso) === 'string'
11+
<% } else if (typeof(theme.comment.isso) === 'string'
1212
|| theme.comment.isso && theme.comment.isso.on) { %>
1313
<%- partial('comment/isso', { script: true }) %>
1414
<% } else if (theme.comment.changyan.on) { %>
1515
<%- partial('comment/changyan', { script: true }) %>
1616
<% } else if (theme.comment.valine.on) { %>
1717
<%- partial('comment/valine', { script: true }) %>
18+
<% } else if (theme.comment.gitalk.on) { %>
19+
<%- partial('comment/gitalk', { script: true }) %>
1820
<% } %>

‎scripts/md5.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* MD5 Hash Helper
3+
* @description Calculate the MD5 hash value of a string
4+
* @example
5+
* <%- md5(data) %>
6+
*/
7+
const crypto = require('crypto');
8+
9+
hexo.extend.helper.register('md5', function (data) {
10+
return crypto.createHash('md5').update(data).digest("hex");
11+
});

1 commit comments

Comments
 (1)

ppoffice commented on Jan 8, 2019

@ppoffice
Owner
This repository has been archived.