Gitment:使用 GitHub Issues 搭建评论系统

nimaboke 2018-2-12 2625

注册 OAuth Application

点击此处 来注册一个新的 OAuth Application。其他内容可以随意填写,但要确保填入正确的 callback URL(一般是评论页面对应的域名,如 https://nimaboke.com )

你会得到一个 client ID 和一个 client secret,这个将被用于之后的用户登录。

引入 Gitment

将下面的代码添加到你的页面:

repo即为项目名称,创建新项目地址:https://github.com/new ghost博客文章标题函数:{{title}} ghost博客文章ID函数:{{comment_id}}

注意,上述代码引用的 Gitment 将会随着开发变动。如果你希望始终使用最新的界面与特性即可引入上述代码。

如果你希望引用确定版本的 Gitment,则应该使用 npm 进行安装。

$ npm install --save gitment 关于构造函数中的更多可用参数请查看 Gitment Options

初始化评论

页面发布后,你需要访问页面并使用你的 GitHub 账号登录(请确保你的账号是第二步所填 repo 的 owner),点击初始化按钮。

之后其他用户即可在该页面发表评论。

自定义

Gitment 很容易进行自定义,你可以写一份自定义的 CSS 或者使用一个新的主题。(主题可以改变 DOM 结构而自定义 CSS 不能)

比如你可以通过自定义主题将评论框放在评论列表前面:

const myTheme = { render(state, instance) { const container = document.createElement('div') container.lang = "en-US" container.className = 'gitment-container gitment-root-container' container.appendChild(instance.renderHeader(state, instance)) container.appendChild(instance.renderEditor(state, instance)) container.appendChild(instance.renderComments(state, instance)) container.appendChild(instance.renderFooter(state, instance)) return container }, } const gitment = new Gitment({ // ... theme: myTheme, }) gitment.render('container') 更多自定义内容请查看文档

另外是支持邮箱提醒的 upload-1517143320.jpg

本文转载自孙士权的博客,原文地址:https://imsun.net/posts/gitment-introduction/


最新回复 (0)
返回
发新帖