Top Related Projects
:crystal_ball: A lightweight comments widget built on GitHub issues
Gitalk is a modern comment component based on Github Issue and Preact.
🌌 Your Self-hosted Comment System. | 自托管评论系统
Quick Overview
Gitment is a comment system based on GitHub Issues. It allows users to add comments to their static websites or blogs using GitHub Issues as the backend, providing a lightweight and customizable commenting solution.
Pros
- Easy integration with static websites and blogs
- Utilizes GitHub authentication, reducing spam and anonymous comments
- Customizable appearance through CSS
- No need for a separate database or backend server
Cons
- Requires users to have a GitHub account to comment
- Limited to 1 MB of comments per page due to GitHub API restrictions
- May not be suitable for high-traffic websites due to API rate limits
- Discontinued and no longer actively maintained
Code Examples
- Basic initialization:
var gitment = new Gitment({
id: 'Your page ID',
owner: 'Your GitHub username',
repo: 'The repo to store comments',
oauth: {
client_id: 'Your client ID',
client_secret: 'Your client secret',
},
})
gitment.render('comments')
- Customizing the theme:
var gitment = new Gitment({
// ... other options
theme: {
render(state, instance) {
// Custom render function
},
bodyPadding: '10px',
},
})
- Manually creating an issue for a page:
gitment.createIssue()
.then(function() {
console.log('Issue created successfully')
})
.catch(function(err) {
console.error(err)
})
Getting Started
- Register an OAuth application in GitHub Settings.
- Include Gitment in your HTML file:
<link rel="stylesheet" href="https://imsun.github.io/gitment/style/default.css">
<script src="https://imsun.github.io/gitment/dist/gitment.browser.js"></script>
- Initialize Gitment in your JavaScript:
var gitment = new Gitment({
id: 'page-id',
owner: 'your-username',
repo: 'your-repo',
oauth: {
client_id: 'your-client-id',
client_secret: 'your-client-secret',
},
})
gitment.render('comments-container')
- Add a container element in your HTML:
<div id="comments-container"></div>
Competitor Comparisons
:crystal_ball: A lightweight comments widget built on GitHub issues
Pros of Utterances
- Lightweight and faster loading times
- No need for a database, as comments are stored as GitHub issues
- Supports multiple authentication methods (GitHub, GitLab, Bitbucket)
Cons of Utterances
- Limited customization options compared to Gitment
- Requires users to have a GitHub account to comment
- Less control over comment moderation
Code Comparison
Gitment initialization:
const gitment = new Gitment({
id: 'Your page ID',
owner: 'Your GitHub ID',
repo: 'The repo to store comments',
oauth: {
client_id: 'Your client ID',
client_secret: 'Your client secret',
},
})
gitment.render('comments')
Utterances setup:
<script src="https://utteranc.es/client.js"
repo="[ENTER REPO HERE]"
issue-term="pathname"
theme="github-light"
crossorigin="anonymous"
async>
</script>
Both Gitment and Utterances are comment systems for static websites that leverage GitHub for storage and authentication. Gitment offers more customization options but requires more setup, while Utterances is simpler to implement and lighter-weight. The choice between them depends on specific project needs and desired level of control over the commenting system.
Gitalk is a modern comment component based on Github Issue and Preact.
Pros of Gitalk
- More active development and maintenance
- Supports multiple authorization methods (GitHub OAuth, Personal Access Token)
- Better internationalization support with multiple language options
Cons of Gitalk
- Slightly more complex setup process
- Requires more configuration options to be set
Code Comparison
Gitment initialization:
var gitment = new Gitment({
id: 'Your page ID',
owner: 'Your GitHub ID',
repo: 'The repo to store comments',
oauth: {
client_id: 'Your client ID',
client_secret: 'Your client secret',
},
})
gitment.render('comments')
Gitalk initialization:
const gitalk = new Gitalk({
clientID: 'GitHub Application Client ID',
clientSecret: 'GitHub Application Client Secret',
repo: 'GitHub repo',
owner: 'GitHub repo owner',
admin: ['GitHub repo owner and collaborators'],
id: location.pathname,
distractionFreeMode: false
})
gitalk.render('gitalk-container')
Both Gitment and Gitalk are comment systems based on GitHub Issues. Gitalk offers more features and active development, while Gitment has a simpler setup process. Gitalk provides better internationalization and multiple authorization methods, but requires more configuration. The code comparison shows that Gitalk's initialization involves more options, reflecting its broader feature set.
🌌 Your Self-hosted Comment System. | 自托管评论系统
Pros of Artalk
- More actively maintained with recent updates
- Supports multiple languages and internationalization
- Offers a wider range of customization options and features
Cons of Artalk
- Requires server-side setup, which may be more complex
- Larger codebase and potentially higher resource usage
- Less integrated with GitHub ecosystem
Code Comparison
Gitment (JavaScript):
const gitment = new Gitment({
id: 'Your page ID',
owner: 'Your GitHub ID',
repo: 'The repo to store comments',
oauth: {
client_id: 'Your client ID',
client_secret: 'Your client secret',
},
})
gitment.render('comments')
Artalk (JavaScript):
new Artalk({
el: '#comments',
server: 'https://your-artalk-server.com',
site: 'Your site name',
pageKey: 'Your page key',
pageTitle: 'Your page title',
placeholder: 'Leave a comment...'
})
Both projects aim to provide commenting systems for websites, but they differ in their approach and features. Gitment leverages GitHub issues for comment storage, making it simpler to set up for GitHub users. Artalk, on the other hand, offers a more comprehensive commenting system with its own backend, providing greater flexibility and customization options at the cost of increased complexity in setup and maintenance.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Gitment
Gitment is a comment system based on GitHub Issues, which can be used in the frontend without any server-side implementation.
Features
- GitHub Login
- Markdown / GFM support
- Syntax highlighting
- Notifications from GitHub
- Easy to customize
- No server-side implementation
Get Started
1. Install
<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 via npm:
$ npm i --save gitment
import 'gitment/style/default.css'
import Gitment from 'gitment'
2. Register An OAuth Application
Click here to register an OAuth application, and you will get a client ID and a client secret.
Make sure the callback URL is right. Generally it's the origin of your site, like https://imsun.net.
3. Render Gitment
const gitment = new Gitment({
id: 'Your page ID', // optional
owner: 'Your GitHub ID',
repo: 'The repo to store comments',
oauth: {
client_id: 'Your client ID',
client_secret: 'Your client secret',
},
// ...
// For more available options, check out the documentation below
})
gitment.render('comments')
// or
// gitment.render(document.getElementById('comments'))
// or
// document.body.appendChild(gitment.render())
4. Initialize Your Comments
After the page is published, you should visit your page, login with your GitHub account(make sure you're repo's owner), and click the initialize button, to create a related issue in your repo. After that, others can leave their comments.
Methods
constructor(options)
options:
Type: object
- owner: Your GitHub ID. Required.
- repo: The repository to store your comments. Make sure you're repo's owner. Required.
- oauth: An object contains your client ID and client secret. Required.
- client_id: GitHub client ID. Required.
- client_secret: GitHub client secret. Required.
- id: An optional string to identify your page. Default
location.href
. - title: An optional title for your page, used as issue's title. Default
document.title
. - link: An optional link for your page, used in issue's body. Default
location.href
. - desc: An optional description for your page, used in issue's body. Default
''
. - labels: An optional array of labels your want to add when creating the issue. Default
[]
. - theme: An optional Gitment theme object. Default
gitment.defaultTheme
. - perPage: An optional number to which comments will be paginated. Default
20
. - maxCommentHeight: An optional number to limit comments' max height, over which comments will be folded. Default
250
.
gitment.render([element])
element
Type: HTMLElement
or string
The DOM element to which comments will be rendered. Can be an HTML element or element's id. When omitted, this function will create a new div
element.
This function returns the element to which comments be rendered.
gitment.renderHeader([element])
Same like gitment.render([element])
. But only renders the header.
gitment.renderComments([element])
Same like gitment.render([element])
. But only renders comments list.
gitment.renderEditor([element])
Same like gitment.render([element])
. But only renders the editor.
gitment.renderFooter([element])
Same like gitment.render([element])
. But only renders the footer.
gitment.init()
Initialize a new page. Returns a Promise
and resolves when initialized.
gitment.update()
Update data and views. Returns a Promise
and resolves when data updated.
gitment.post()
Post comment in the editor. Returns a Promise
and resolves when posted.
gitment.markdown(text)
text
Type: string
Returns a Promise
and resolves rendered text.
gitment.login()
Jump to GitHub OAuth page to login.
gitment.logout()
Log out current user.
goto(page)
page
Type: number
Jump to the target page of comments. Notice that page
starts from 1
. Returns a Promise
and resolves when comments loaded.
gitment.like()
Like current page. Returns a Promise
and resolves when liked.
gitment.unlike()
Unlike current page. Returns a Promise
and resolves when unliked.
gitment.likeAComment(commentId)
commentId
Type: string
Like a comment. Returns a Promise
and resolves when liked.
gitment.unlikeAComment(commentId)
commentId
Type: string
Unlike a comment. Returns a Promise
and resolves when unliked.
Customize
Gitment is easy to customize. You can use your own CSS or write a theme. (The difference is that customized CSS can't modify DOM structure)
Use Customized CSS
Gitment does't use any atomic CSS, making it easier and more flexible to customize. You can inspect the DOM structure in the browser and write your own styles.
Write A Theme
A Gitment theme is an object contains several render functions.
By default Gitment has five render functions: render
, renderHeader
, renderComments
, renderEditor
, renderFooter
.
The last four render independent components and render
functions render them together.
All of them can be used independently.
You can override any render function above or write your own render function.
For example, you can override the render
function to put an editor before the comment list, and render a new component.
const myTheme = {
render(state, instance) {
const container = document.createElement('div')
container.lang = "en-US"
container.className = 'gitment-container gitment-root-container'
// your custom component
container.appendChild(instance.renderSomething(state, instance))
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
},
renderSomething(state, instance) {
const container = document.createElement('div')
container.lang = "en-US"
if (state.user.login) {
container.innerText = `Hello, ${state.user.login}`
}
return container
}
}
const gitment = new Gitment({
// ...
theme: myTheme,
})
gitment.render(document.body)
// or
// gitment.renderSomthing(document.body)
Each render function should receive a state object and a gitment instance, and return an HTML element. It will be wrapped attached to the Gitment instance with the same name.
Gitment uses MobX to detect states used in render functions. Once used states change, Gitment will call the render function to get a new element and render it. Unused states' changing won't affect rendered elements.
Available states:
- user:
object
. User info returned from GitHub Users API with two more keys.- isLoggingIn:
bool
. Indicates if user is logging in. - fromCache:
bool
. Gitment will cache user's information. Its value indicates if current user info is from cache.
- isLoggingIn:
- error:
Error Object
. Will be null if no error occurs. - meta:
object
. Issue's info returned from GitHub Issues API. - comments:
array
. Array of comment returned from GitHub Issue Comments API. Will beundefined
when comments not loaded. - reactions:
array
. Array of reactions added to current page, returned from GitHub Issues' Reactions API. - commentReactions:
object
. Object of reactions added to comments, with comment ID as key, returned from GitHub Issue Comments' Reactions API. - currentPage:
number
. Which page of comments is user on. Starts from1
.
About Security
Is it safe to make my client secret public?
Client secret is necessary for OAuth, without which users can't login or comment with their GitHub accounts. Although GitHub does't recommend to hard code client secret in the frontend, you can still do that because GitHub will verify your callback URL. In theory, no one else can use your secret except your site.
If you find a way to hack it, please open an issue.
Why does Gitment send a request to gh-oauth.imsun.net?
https://gh-oauth.imsun.net is an simple open-source service to proxy one request during users logging in. Because GitHub doesn't attach a CORS header to it.
This service won't record or store anything. It only attaches a CORS header to that request and provides proxy. So that users can login in the frontend without any server-side implementation.
For more details, checkout this project.
Top Related Projects
:crystal_ball: A lightweight comments widget built on GitHub issues
Gitalk is a modern comment component based on Github Issue and Preact.
🌌 Your Self-hosted Comment System. | 自托管评论系统
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot