1
0
Fork 0

feat: add gitalk support

This commit is contained in:
peanut996 2023-09-09 17:05:09 +08:00
parent 62dd140436
commit 7fff7e482e
2 changed files with 33 additions and 0 deletions
README.md
layouts/_default

View file

@ -63,6 +63,14 @@ disqusShortname = 'YOUR_DISQUS_SHORTNAME' # use disqus comments
gravatarCdn = 'GRAVATAR_CDN_LINK' # e.g. 'https://cdn.v2ex.com/gravatar/'
graphCommentId = "YOUR_GRAPH_COMMENT_ID" # use graph comment (disqus alternative)
math = true # enable KaTeX math typesetting globally
# your git talk config
[params.gitalk]
enable = true
clientID = 'gitalk client id'
clientSecret = 'gitalk client secret'
repo = 'your gitalk repo'
owner = 'owner github username'
```
Available options to front matter:

View file

@ -100,6 +100,31 @@
})();
</script>
{{ end }}
<!-- Gitalk -->
{{ if and .Site.Params.Gitalk.enable (not (eq .Params.comments false)) }}
<div id="gitalk-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>
const gitalk = new Gitalk({
clientID: '{{ .Site.Params.Gitalk.clientID }}',
clientSecret: '{{ .Site.Params.Gitalk.clientSecret }}',
repo: '{{ .Site.Params.Gitalk.repo }}',
owner: '{{ .Site.Params.Gitalk.owner }}',
admin: ['{{ .Site.Params.Gitalk.owner }}'],
id: location.pathname, // Ensure uniqueness and length less than 50
distractionFreeMode: false // Facebook-like distraction free mode
});
(function() {
if (["localhost", "127.0.0.1"].indexOf(window.location.hostname) != -1) {
document.getElementById('gitalk-container').innerHTML = 'Gitalk comments not available by default when the website is previewed locally.';
return;
}
gitalk.render('gitalk-container');
})();
</script>
{{ end }}
</article>
{{ end }}