上一篇:Hexo 搭建个人博客教程 - 6 - 设置菜单,发布博客
Gitment是imsun实现的一款基于GitHub Issues的评论系统
github地址:https://github.com/imsun/gitment
支持在前端直接引入,不需要任何后端代码。可以在页面进行登录、查看、评论、点赞等操作
效果预览
安装及配置
登录github,打开settings -> Developer settings
https://github.com/settings/developers
点击Register a new application
Application name 随便写
Homepage URL 博客地址
Application description 随便写
Authorization callback URL 博客地址
保存之后,我们就获取到了Client ID和Client Secret
引入 Gitment
在需要添加评论的文章下新增
<div id="container"></div> <link rel="stylesheet" href="https://imsun.github.io/gitment/style/default.css"> <script src="https://imsun.github.io/gitment/dist/gitment.browser.js"></script> <script> var gitment = new Gitment({ id: '页面 ID', // 可选。默认为 location.href owner: '你的 GitHub ID', repo: '存储评论的 repo', oauth: { client_id: '你的 client ID', client_secret: '你的 client secret', }, }) gitment.render('container') </script>
注意:
id 不可重复,最大长度限制是50个字符,我使用的当前页面的生产日期如:201807251230
owner:gitHub用户名,也可以是github id ,注意大小写
repo:gitHub仓库名称,不需要写地址,如我的:faceghost.github.io
client_id:上面获取的client_id
client_secret:上面获取的client_secret
注意,上述代码引用的 Gitment 将会随着开发变动。如果你希望始终使用最新的界面与特性即可引入上述代码。
如果你希望引用确定版本的 Gitment,则应该使用 npm 进行安装。
npm install --save gitment
文章一键初始化评论
配置正确的文章,第一次显示,提示还没有初始化,登录你的GitHub初始化即可