惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Stack Overflow Blog
Stack Overflow Blog
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
N
Netflix TechBlog - Medium
腾讯CDC
C
Check Point Blog
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
S
SegmentFault 最新的问题
F
Fortinet All Blogs
美团技术团队
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
F
Full Disclosure
Recorded Future
Recorded Future
D
DataBreaches.Net
博客园 - 【当耐特】
Martin Fowler
Martin Fowler
J
Java Code Geeks
I
InfoQ
Y
Y Combinator Blog
A
About on SuperTechFans
AI
AI
爱范儿
爱范儿
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Forbes - Security
Forbes - Security
W
WeLiveSecurity
M
MIT News - Artificial intelligence
雷峰网
雷峰网
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
Schneier on Security
Schneier on Security
The GitHub Blog
The GitHub Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Docker
Recent Commits to openclaw:main
Recent Commits to openclaw:main
量子位
V2EX - 技术
V2EX - 技术
Project Zero
Project Zero

CodeBlocQ

Jest - Mock Local Storage Have Mobx and React work with TypeScript Loose assertions on arguments passed to function with Jest TypeScript Abstract Class Check if a Docker image exists locally A-Star Pathfinding React Demo My Free and Open Source Expense Tracker App is on the App Store Pass artifacts around in between stages in gitlab CI How to start a tech company as a non technical individual
Setup gitment on your Hexo blog
Jonathan Klughertz · 2018-05-27 · via CodeBlocQ

After 2 years running disqus on my blog, I have decided to switch over to gitment. The spam and slowness of Disqus is what drove me away from it. Plus no more ads for users.

Gitment is a small JS library that leverages on Github issues to store comments for each post:

  • Each post will have a matching Github issue (example for this blog).
  • Users will have to be logged in to github to post.
  • Comments are saved as github comments on each issue/post
  • Gitment takes care of displaying a form that allows users to see/post comments

Let’s get started.

Installation

You can use the hosted libraries:

<link rel="stylesheet" href="https://imsun.github.io/gitment/style/default.css">
<script src="https://imsun.github.io/gitment/dist/gitment.browser.js"></script>

or build them yourself

git clone git@github.com:imsun/gitment.git
cd gitment
npm install
npm build

Once you are sure that gitment.browser.js and default.css are present on your site, let’s move on to the setup.

Setup Github

First of all we are going to need an OAuth application.

  • Click here to register an OAuth application.
  • Save the client ID and client secret somewhere.
  • For the callback URL, use the same domain as your blog (I am using http://www.codeblocq.com/).

Integrate Gitment in Hexo

Let’s add a new configuration object to store our client Id and Secret. In your theme’s _config.yml, add:


comments:
gitment:
clientId: 1808dbefdea3c185dd3b
clientSecret: 557be2aa0aa72bdffe0f22c683b7516166b0be28

We now need a <div> container to tell gitment where to display the comments:

This is how I did it: (note the id="gitment-comments")

<% if{ %>
<div id="gitment-comments"></div>
<% } %>

and we are now ready to initialize the gitment library:

<script>
const gitment = new Gitment({
id: '<%= page.title.replace(/[^\w\s]/gi, '').substring(0, 49) %>',
owner: 'your-github-id',
repo: 'your-repo-name',
oauth: {
client_id: '<%= theme.comments.gitment.clientId %>',
client_secret: '<%= theme.comments.gitment.clientSecret %>'
}
});

gitment.render(document.getElementById('gitment-comments'));
</script>

Important:

  • the id should be a unique identifier for each post. Gitment will use it as the matching github issue name + will create one label with that id as well. Special character are not allowed and the max length is 50 chars. Make sure your use the regexp above to avoid issues down the line.
  • this script needs to be executed AFTER the <div id="gitment-comments"></div> has rendered, so make sure you place that script tag at the end of the <body> or at least after the div.
  • Use your github hanlde as owner
  • Create a repo that will be used to store the issues. Since my blog is hosted on github pages, I am using that repository.

At this point, deploy your blog and visit each page while logged in on github.

Click the Initialize comments link on each page to open a comment thread (aka create a github issue) for that particular post.

Results below ;)