GithubHelp home page GithubHelp logo

gitalk / gitalk Goto Github PK

View Code? Open in Web Editor NEW
6.9K 49.0 616.0 3.56 MB

Gitalk is a modern comment component based on Github Issue and Preact.

Home Page: https://gitalk.github.io

License: MIT License

HTML 0.98% JavaScript 82.51% Stylus 16.52%
comment plugin github github-issues preact react

gitalk's Introduction

Gitalk

NPM CDNJS jsdelivr david-dm travis coveralls gzip-size

Gitalk is a modern comment component based on GitHub Issue and Preact.

Features

  • Authentication with github account
  • Serverless, all comments will be stored as github issues
  • Both personal and organization github projects can be used to store comments
  • Localization, support multiple languages [en, zh-CN, zh-TW, es-ES, fr, ru, de, pl, ko, fa, ja]
  • Facebook-like distraction free mode (Can be enabled via the distractionFreeMode option)
  • Hotkey submit comment (cmd|ctrl + enter)

中文说明 Demo

Install

Two ways.

  • links
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
  <script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>

  <!-- or -->

  <link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css">
  <script src="https://unpkg.com/gitalk/dist/gitalk.min.js"></script>
  • npm install
npm i --save gitalk
import 'gitalk/dist/gitalk.css'
import Gitalk from 'gitalk'

Usage

Firstly, you need choose a public github repository (existed or create a new one) for store comments,

Then create A GitHub Application if you don't have one, Click here to register a new one. Note: You must specify the website domain url in the Authorization callback URL field.

Lastly, you can choose how to apply to the page as below:

Method One

Add a container to your page:

<div id="gitalk-container"></div>

Then use the Javascript code below to generate the gitalk plugin:

const gitalk = new Gitalk({
  clientID: 'GitHub Application Client ID',
  clientSecret: 'GitHub Application Client Secret',
  repo: 'GitHub repo',      // The repository of store comments,
  owner: 'GitHub repo owner',
  admin: ['GitHub repo owner and collaborators, only these guys can initialize github issues'],
  id: location.pathname,      // Ensure uniqueness and length less than 50
  distractionFreeMode: false  // Facebook-like distraction free mode
})

gitalk.render('gitalk-container')

Method Two: Use in React

Import the Gitalk with

import GitalkComponent from "gitalk/dist/gitalk-component";

And use the component like

<GitalkComponent options={{
  clientID: "...",
  // ...
  // options below
}} />

Options

  • clientID String

    Required. GitHub Application Client ID.

  • clientSecret String

    Required. GitHub Application Client Secret.

  • repo String

    Required. GitHub repository.

  • owner String

    Required. GitHub repository owner. Can be personal user or organization.

  • admin Array

    Required. GitHub repository owner and collaborators. (Users who having write access to this repository)

  • id String

    Default: location.href.

    The unique id of the page. Length must less than 50.

  • number Number

    Default: -1.

    The issue ID of the page, if the number attribute is not defined, issue will be located using id.

  • labels Array

    Default: ['Gitalk'].

    GitHub issue labels.

  • title String

    Default: document.title.

    GitHub issue title.

  • body String

    Default: location.href + header.meta[description].

    GitHub issue body.

  • language String

    Default: navigator.language || navigator.userLanguage.

    Localization language key, support [en, zh-CN, zh-TW, es-ES, fr, ru, de, pl, ko, fa, ja].

  • perPage Number

    Default: 10.

    Pagination size, with maximum 100.

  • distractionFreeMode Boolean

    Default: false.

    Facebook-like distraction free mode.

  • pagerDirection String

    Default: 'last'

    Comment sorting direction, available values are last and first.

  • createIssueManually Boolean

    Default: false.

    By default, Gitalk will create a corresponding github issue for your every single page automatically when the logined user is belong to the admin users. You can create it manually by setting this option to true.

  • proxy String

    Default: https://cors-anywhere.azm.workers.dev/https://github.com/login/oauth/access_token.

    GitHub oauth request reverse proxy for CORS. Why need this?

  • flipMoveOptions Object

    Default:

      {
        staggerDelayBy: 150,
        appearAnimation: 'accordionVertical',
        enterAnimation: 'accordionVertical',
        leaveAnimation: 'accordionVertical',
      }

    Comment list animation. Reference

  • enableHotKey Boolean

    Default: true.

    Enable hot key (cmd|ctrl + enter) submit comment.

Instance Methods

  • render(String/HTMLElement)

    Init render and mount plugin.

TypeScript

TypeScript definitions for options and Gitalk class come with the package and should be automatically detected.

Definitions for React component usage are not included.

Contributing

  1. Fork the repository and create your branch from master
  2. If you've added code that should be tested, add tests!
  3. If you've changed APIs, update the documentation.
  4. Ensure the test suite passes (npm test).
  5. Make sure your code lints (npm run lint).
  6. Commit your changes (git commit) Commit Message Format Reference

Similar Projects

LICENSE

MIT

gitalk's People

Contributors

ahonn avatar azl397985856 avatar booxood avatar coderming avatar colynn avatar dependabot[bot] avatar devrsi0n avatar dingqianwen avatar dongyuanxin avatar fletchto99 avatar geektutu avatar jungwngkim avatar lukasdrgon avatar mamboer avatar masterhiei avatar mateusznakodach avatar meteorlxy avatar mhuig avatar ricardocasares avatar saeedesmaili avatar sergeyyarkov avatar spiritree avatar steve84 avatar tubone24 avatar vdeville avatar wolfsilver avatar xnng avatar yokinist avatar zce avatar zqjimlove avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gitalk's Issues

关于评论编辑的建议

在Gitalk评论系统中,编辑已经评论过的文字会自动跳转到Issue页面,可不可以优化一下,直接在原页面上编辑评论?

提供方法修改 perPage 屬性

現在, perPage 屬性是在 gitalk.jsx 裡面的 constructor (第56行)構建的。

我想在構建gitalk之後,可以再次手動設置屬性 perPage 屬性,再次自行定義每個頁面的評論載入量。

  • 提供 setPerPage(page: number) 方法

请问如何完全(永久)取消某个 issue 订阅

我在 demo 中回复了一条评论,导致之后一旦有人新增评论,我就会收到邮件提醒,我想原因是评论后就会默认订阅这个 issue,即使别人不是回复你,也会收到提醒。

于是我进入到 demo 相关的具体 issue,点击了 unsubscribe,取消订阅,可是后续有人评论,仍然给我发提醒邮件了,而且我的账号再次被置为订阅了该 issue,对此十分困扰,不知如何才能完全取消评论订阅。

image

新增繁體中文 README.md

我覺得這個評論很實用,我會寫一篇文章,並翻譯 README.md。
// TODO:

  • 翻譯為繁體中文
  • 附上代碼解釋

自动化初始所有评论的脚本

昨天写了个自动化初始评论的脚本

username = "draveness" # GitHub 用户名
new_token = "xxxxxxx"  # GitHub Token
repo_name = "github-comments-repo" # 存放 issues
sitemap_url = "https://draveness.me/sitemap.xml" # sitemap
kind = "Gitalk" # "Gitalk" or "gitment"

require 'open-uri'
require 'faraday'
require 'active_support'
require 'active_support/core_ext'
require 'sitemap-parser'

sitemap = SitemapParser.new sitemap_url
urls = sitemap.to_a

conn = Faraday.new(:url => "https://api.github.com/repos/#{username}/#{repo_name}/issues") do |conn|
  conn.basic_auth(username, token)
  conn.adapter  Faraday.default_adapter
end

urls.each_with_index do |url, index|
  title = open(url).read.scan(/<title>(.*?)<\/title>/).first.first.force_encoding('UTF-8')
  response = conn.post do |req|
    req.body = { body: url, labels: [kind, url], title: title }.to_json
  end
  puts response.body
  sleep 15 if index % 20 == 0
end

详细使用可以看:https://draveness.me/git-comments-initialize

use gitalk in docsify

insert code in index.html

<link rel="stylesheet" href="//unpkg.com/gitalk/dist/gitalk.css">

<script src="//unpkg.com/docsify/lib/plugins/gitalk.min.js"></script>
<script src="//unpkg.com/gitalk/dist/gitalk.min.js"></script>
<script>
  const gitalk = new Gitalk({
    clientID: 'Github Application Client ID',
    clientSecret: 'Github Application Client Secret',
    repo: 'Github repo',
    owner: 'Github repo owner',
    admin: ['Github repo collaborators, only these guys can initialize github issues'],
    // facebook-like distraction free mode
    distractionFreeMode: false
  })
</script>

有加入Hexo博客的简单方法么

之前用的来必力,这两天貌似挂了。后来试了一下Gitment,不过有些麻烦,每篇文章得手动初始化才能创建一个Issue,才能评论。这个我看了下demo,感觉界面不错,不过有加入hexo博客的比较方便的方法么,像Next主题那种的?

issue重复

每点击(刷新)文章页面一次,就会新建一个issue,结果就是相同的文章会有很多issue

评论自动订阅issue的问题

我看了下 #15 里面有了一些讨论,现在有个想法不知道能不能实现

首先在gitalk里面有一个“回复”按钮
点击回复后会@该用户

另外如果我们取消订阅,被@还是会收到提醒,不被@则不会收到提醒
那么按照这个逻辑,只要我们取消了订阅,就是正常的评论提醒功能了

1.如果有人@你,你会收到邮件提醒,因为他是回复你的,你应该收到提醒
2.没有人@你,直接评论的,你不会收到提醒,因为这条评论和你没关系

所以只需要在评论后,自动取消订阅就可以不被*扰了。
可以实现自动取消订阅么,或者在页面添加一个选项?

Gitalk Demo

https://gitalk.github.io/

This is just a demo, and welcome your comments. If you have any questions or suggestions, please make another issue. Thank you.

这里只是作为演示,欢迎大家留言体验。如果有任何问题或者建议,请另外提 issue,谢谢。

目前无法点击评论的问题

我按照read me中指示的那样,在hexo的主题中使用,但是无法点击评论这个按钮,手机页面可以点击。设备是mac chrome

关于回复评论的建议

能不能将回复做到评论的下面,否则如果评论很多的话,回复和原问题都连不到一块,很难找

另外这是一个非常好的 repo,谢谢 👍

构建项目报错

参数id不希望成为labels的参数。于是下载了项目修改代码重新构建。构建过程如下:

$ git clone xx
$ npm i
$ npm run dev

出现如下报错:

ERROR in ./src/index.js
Module parse failed: ~/gitalk/src/index.js Unexpected token (23:18)
You may need an appropriate loader to handle this file type.
|     }
|
|     return render(<GitalkComponent options={this.options}/>, node)
|   }
| }
 @ multi (webpack)-dev-server/client?http://localhost:8000 webpack/hot/dev-server ./index.js

Gitalk支持组织了!

新的页面,登陆后显示如题报错,评论不了。是因为没有初始化新建issue吗?需要自己建吗?

issue 自动创建问题

只有配置的 admin 成员打开页面才会自动创建 issue 吗?能设置不管是谁打开如果不存在就创建吗? 不然得把之前所有博文都点击一次太麻烦了

Error: Not Found.

如题,而且点击登陆也登陆不了,直接刷新页面,不知道怎么解决,有知道的可以帮忙解决一下吗。谢谢!~

给用hexo的小伙伴一点福利

在comments文件夹下新建一个文件 gitalk.ejs

<link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css">
<script src="https://yiyeti.cc/usr/themes/veryse/css/gitalk.min.js"></script>
<div id="gitalk-container"></div>
<script type="text/javascript">
    var gitalk = new Gitalk({
        clientID: '<%= theme.gitalk.clientID %>',
        clientSecret: '<%= theme.gitalk.clientSecret %>',
        id: window.location.pathname,
        repo: '<%= theme.gitalk.repo %>',
        owner: '<%= theme.gitalk.owner %>',
        admin: '<%= theme.gitalk.admin %>',
        distractionFreeMode: '<%= theme.gitalk.on %>'
    })
    gitalk.render('gitalk-container')
</script>

在配置文件 disqus 下面添加新的配置

gitalk:
  on: true
  owner: 你的github账户名
  repo: 你要作为评论系统的repo
  admin: ['github用户名']
  clientID: 你的clientId
  clientSecret: 你的clientSecret

在article.ejs里引用评论

<% if (!index && post.comments){ %>
<% if (theme.duoshuo.on) { %>
<%- partial('comments/duoshuo', {
    key: post.path,
    title: post.title,
    url: config.url + url_for(post.path),
}) %>
<% } else if (theme.changyan.on) { %>
<%- partial('comments/changyan') %>
<% } else if (theme.gitalk.on) { %>
<%- partial('comments/gitalk') %>
<% } else if (config.disqus_shortname) { %>
<%- partial('comments/disqus', {
    shortname: config.disqus_shortname
}) %>
<% } %>

gitak获取不到评论...?

刚开始再博客上评论可以显示评论内容,过一段时间就不能显示评论内容了。而存放评论的issues下有评论,但博客上获取不到......

labels 是否可以考虑去除id

id如果默认为location.href,也看到凹凸博客的加密的字符串,去看issus的时候长长的的label显得很不雅观,建议使用tags(当然这个可以自行配置)

当前评论框所在页面的 URI 中存在中文时无法登陆

当前评论框所在页面的 URI 中存在中文时,点击登陆后会跳转到网站首页,URI 中有如下错误信息

?error=redirect_uri_mismatch&error_description=The+redirect_uri+MUST+match+the+registered+callback+URL+for+this+application.&error_uri=https%3A%2F%2Fdeveloper.github.com%2Fv3%2Foauth%2F%23redirect-uri-mismatch```

提高移动端兼容性

我在自己手机上测试了

  • 安卓UC最新版浏览器
  • 魅族自带浏览器

均不显示评论区...和gitment一样

20170913213951

但是我曾使用别人修改后的版本,解决了这个问题
可以参考下:imsun/gitment#52

【需求】建议添加点赞功能

有回复功能,非常不错!
但是还缺一个对整个文章或者某条评论点赞的按钮。建议添加对页面、对每条评论的点赞按钮,按钮链接到 issue 中 Add your reaction 功能。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.