apollo主题下使用gitment

226 阅读1分钟
原文链接: yangsoon.github.io

前言

之前一直没在blog下添加评论系统,多说貌似不干了,偶然间发现了gitment,它是一款基于GitHub Issues 的评论系统,同时有完整的 Markdown / GFM 和代码高亮支持。感觉不错,就添加到blog下了。

方法

1. 注册 OAuth Application

点击此处 来注册一个新的 OAuth Application。其他内容可以随意填写,但要确保填入正确的 callback URL(一般是评论页面对应的域名) 你会得到一个 client ID 和一个 client secret,这个将被用于之后的用户登录。

2. 引入Gitment

因为使用的是apollo主题,所以我们先配置 _config.yml 文件。只需要添加几行代码就行。

# Comment
# e.g disqus: seansun
disqus:
duoshuo:
gitment:
    enable: true
    owner: yangsoon
    repo: yangsoon.github.io
    client_id: ************
    client_secret: ************

下面我们修改 /themes/apollo/layout/partial 目录下的 comment.jade 文件, 在末尾加入就行。

if theme.gitment.enable
    - var data = page.date
    #container
    link(rel='stylesheet', href='https://imsun.github.io/gitment/style/default.css')
    script(src='https://imsun.github.io/gitment/dist/gitment.browser.js')
    script.
        var gitment = new Gitment({
            id: '#{data}',
            owner: '#{theme.gitment.owner}',
            repo: '#{theme.gitment.repo}',
            oauth: {
                client_id: '#{theme.gitment.client_id}',
                client_secret: '#{theme.gitment.client_secret}',
            },
        })
        gitment.render('container')

之后将静态页面提交到github上查看就行了,一些细节还是看看官方文档吧。

参考

imsun.net/posts/gitme…
github.com/imsun/gitme…
wf94.github.io/2017/04/14/…