Skip to content

Commit

Permalink
feat: add Gitalk comments support (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
h1z3y3 committed Apr 15, 2021
1 parent abd67d8 commit 6941bd2
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 0 deletions.
17 changes: 17 additions & 0 deletions config-examples/en/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,23 @@ uglyURLs = false
# `comments` in post’s Front Matter
# has a higher priority than here

## Gitalk
enableGitalk = false
gitalkClientID = "your_client_id"
gitalkClientSecret = "your_client_secret"
gitalkRepo = "your_repository"
gitalkOwner = "your_gitalk_owner"
gitalkAdmin = ["your_gitalk_admin"]
gitalkLable = ["Gitalk"]
gitalkDistractionFreeMode = false
gitalkPerPage = 10
gitalkLanguage = "en"
gitalkPagerDirection = "last"
gitalkCreateIssueManually = false
gitalkProxy = "https://cors-anywhere.azm.workers.dev/https://github.com/login/oauth/access_token"
gitalkEnableHotKey = true
# Note: https://github.com/gitalk/gitalk

## Disqus
enableDisqus = false
disqusShortname = ""
Expand Down
17 changes: 17 additions & 0 deletions config-examples/zh-cn/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,23 @@ uglyURLs = false
# 说明:文章的 Front Matter 中的 `comments`
# 的优先级高于此处

## Gitalk
enableGitalk = false
gitalkClientID = "your_client_id"
gitalkClientSecret = "your_client_secret"
gitalkRepo = "your_repository"
gitalkOwner = "your_gitalk_owner"
gitalkAdmin = ["your_gitalk_admin"]
gitalkLable = ["Gitalk"]
gitalkDistractionFreeMode = false
gitalkPerPage = 10
gitalkLanguage = "en"
gitalkPagerDirection = "last"
gitalkCreateIssueManually = false
gitalkProxy = "https://cors-anywhere.azm.workers.dev/https://github.com/login/oauth/access_token"
gitalkEnableHotKey = true
# 说明:https://github.com/gitalk/gitalk

## Disqus
enableDisqus = false
disqusShortname = ""
Expand Down
17 changes: 17 additions & 0 deletions config-examples/zh-tw/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,23 @@ uglyURLs = false
# 說明:文章的 Front Matter 中的 `comments`
# 的優先順序高於此處

## Gitalk
enableGitalk = false
gitalkClientID = "your_client_id"
gitalkClientSecret = "your_client_secret"
gitalkRepo = "your_repository"
gitalkOwner = "your_gitalk_owner"
gitalkAdmin = ["your_gitalk_admin"]
gitalkLable = ["Gitalk"]
gitalkDistractionFreeMode = false
gitalkPerPage = 10
gitalkLanguage = "en"
gitalkPagerDirection = "last"
gitalkCreateIssueManually = false
gitalkProxy = "https://cors-anywhere.azm.workers.dev/https://github.com/login/oauth/access_token"
gitalkEnableHotKey = true
# 說明:https://github.com/gitalk/gitalk

## Disqus
enableDisqus = false
disqusShortname = ""
Expand Down
3 changes: 3 additions & 0 deletions layouts/partials/components/comments.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@
<div id="utterances"></div>
{{ end }}

{{ if .Site.Params.enableGitalk }}
<div id="gitalk-container"></div>
{{ end }}
{{ end }}
{{ end }}
44 changes: 44 additions & 0 deletions layouts/partials/third-party/gitalk.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
<script>
function loadComments() {
if (typeof Gitalk === 'undefined') {
var getScript = (options) => {
var script = document.createElement('script');
script.defer = true;
script.crossOrigin = 'anonymous';
Object.keys(options).forEach((key) => {
script[key] = options[key];
});
document.body.appendChild(script);
};
getScript({
src: 'https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js',
onload: () => {
newGitalk();
}
});
} else {
newGitalk();
}
}
function newGitalk() {
const gitalk = new Gitalk({
clientID: {{ .Site.Params.gitalkClientID }},
clientSecret: {{ .Site.Params.gitalkClientSecret }},
repo: {{ .Site.Params.gitalkRepo }},
owner: {{ .Site.Params.gitalkOwner }},
admin: {{ .Site.Params.gitalkAdmin }},
labels: {{ .Site.Params.gitalkLable }},
distractionFreeMode: {{ .Site.Params.gitalkDistractionFreeMode }},
perPage: {{ .Site.Params.gitalkPerPage }},
language: {{ .Site.Params.gitalkLanguage }},
pagerDirection: {{ .Site.Params.gitalkPagerDirection }},
createIssueManually: {{ .Site.Params.gitalkDistractionFreeMode }},
proxy: {{ .Site.Params.gitalkProxy }},
enableHotKey: {{ .Site.Params.gitalkEnableHotKey }},
id: location.pathname
})

gitalk.render('gitalk-container')
}
</script>
4 changes: 4 additions & 0 deletions layouts/partials/third-party/script.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
{{ partial "third-party/utterances.html" . }}
{{ end }}

{{ if .Site.Params.enableGitalk }}
{{ partial "third-party/gitalk.html" . }}
{{ end }}

{{ end }}
{{ end }}

Expand Down

0 comments on commit 6941bd2

Please sign in to comment.