Skip to content

Commit 9208e64

Browse files
spiritreeQingWei-Li
authored andcommitted
feat: add gitalk plugin (#306)
1 parent 4053491 commit 9208e64

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

build/build.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ var plugins = [
4949
{ name: 'front-matter', entry: 'front-matter/index.js' },
5050
{ name: 'zoom-image', entry: 'zoom-image.js' },
5151
{ name: 'codesponsor', entry: 'codesponsor.js' },
52-
{ name: 'disqus', entry: 'disqus.js' }
52+
{ name: 'disqus', entry: 'disqus.js' },
53+
{ name: 'gitalk', entry: 'gitalk.js' }
5354
]
5455

5556
plugins.forEach(item => {

docs/plugins.md

+22
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,25 @@ Disqus comments. https://disqus.com/
161161
</script>
162162
<script src="//unpkg.com/docsify/lib/plugins/disqus.min.js"></script>
163163
```
164+
165+
## Gitalk
166+
167+
Gitalk is a modern comment component based on Github Issue and Preact. https://github.com/gitalk/gitalk
168+
169+
```html
170+
<link rel="stylesheet" href="//unpkg.com/gitalk/dist/gitalk.css">
171+
172+
<script src="//unpkg.com/docsify/lib/plugins/gitalk.min.js"></script>
173+
<script src="//unpkg.com/gitalk/dist/gitalk.min.js"></script>
174+
<script>
175+
const gitalk = new Gitalk({
176+
clientID: 'Github Application Client ID',
177+
clientSecret: 'Github Application Client Secret',
178+
repo: 'Github repo',
179+
owner: 'Github repo owner',
180+
admin: ['Github repo collaborators, only these guys can initialize github issues'],
181+
// facebook-like distraction free mode
182+
distractionFreeMode: false
183+
})
184+
</script>
185+
```

src/plugins/gitalk.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function install (hook, vm) {
2+
const dom = Docsify.dom
3+
4+
hook.mounted(_ => {
5+
const div = dom.create('div')
6+
div.id = 'gitalk-container'
7+
const main = dom.getNode('#main')
8+
div.style = `width: ${main.clientWidth}px; margin: 0 auto 20px;`
9+
dom.appendTo(dom.find('.content'), div)
10+
const script = dom.create('script')
11+
const content = `gitalk.render('gitalk-container')`
12+
script.textContent = content
13+
dom.appendTo(dom.body, script)
14+
})
15+
}
16+
17+
$docsify.plugins = [].concat(install, $docsify.plugins)

0 commit comments

Comments
 (0)