@clina_z/cotalk
v1.8.6
Published
A comment plugin base on Codeberg issues
Readme
Cotalk
A comment plugin based on Codeberg issues.
Cotalk is a modern comment component based on Codeberg Issue and Preact.
Features
- Authentication with Codeberg account
- Serverless, all comments will be stored as Codeberg issues
- Both personal and organization Codeberg 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
distractionFreeModeoption) - Hotkey submit comment (cmd|ctrl + enter)
Install
Two ways.
- npm install
npm i --save cotalkimport 'cotalk/dist/cotalk.css'
import Cotalk from 'cotalk'Usage
Firstly, you need choose a public Codeberg repository (existed or create a new one) for store comments,
Then create A Codeberg 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="cotalk-container"></div>Then use the Javascript code below to generate the Cotalk plugin:
const cotalk = new Cotalk({
clientID: 'Codeberg Application Client ID',
clientSecret: 'Codeberg Application Client Secret',
repo: 'Codeberg repo', // The repository of store comments,
owner: 'Codeberg repo owner',
admin: ['Codeberg repo owner and collaborators, only these guys can initialize codeberg issues'],
id: location.pathname, // Ensure uniqueness and length less than 50
distractionFreeMode: false // Facebook-like distraction free mode
})
cotalk.render('cotalk-container')Method Two: Use in React
Import the Cotalk with
import CotalkComponent from "cotalk/dist/cotalk-component";And use the component like
<CotalkComponent options={{
clientID: "...",
// ...
// options below
}} />Options
clientID
StringRequired. Codeberg Application Client ID.
clientSecret
StringRequired. Codeberg Application Client Secret.
repo
StringRequired. Codeberg repository.
owner
StringRequired. Codeberg repository owner. Can be personal user or organization.
admin
ArrayRequired. Codeberg repository owner and collaborators. (Users who having write access to this repository)
id
StringDefault:
location.href.The unique id of the page. Length must less than 50.
Note: You can use regex to extract certain path of the URL as the id. E.g.,
location.href.match('/(?<=posts/)(.*)(?=/)/')[1]number
NumberDefault:
-1.The issue ID of the page, if the
numberattribute is not defined, issue will be located usingid.labels
ArrayDefault:
['Gitalk'].GitHub issue labels.
title
StringDefault:
document.title.GitHub issue title.
body
StringDefault:
location.href + header.meta[description].GitHub issue body.
language
StringDefault:
navigator.language || navigator.userLanguage.Localization language key, support [
en,zh-CN,zh-TW,es-ES,fr,ru,de,pl,ko,fa,ja].perPage
NumberDefault:
10.Pagination size, with maximum 100.
distractionFreeMode
BooleanDefault: false.
Facebook-like distraction free mode.
pagerDirection
StringDefault: 'last'
Comment sorting direction, available values are
lastandfirst.createIssueManually
BooleanDefault:
false.By default, Gitalk will create a corresponding github issue for your every single page automatically when the logined user is belong to the
adminusers. You can create it manually by setting this option totrue.flipMoveOptions
ObjectDefault:
{ staggerDelayBy: 150, appearAnimation: 'accordionVertical', enterAnimation: 'accordionVertical', leaveAnimation: 'accordionVertical', }Comment list animation. Reference
enableHotKey
BooleanDefault:
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
- Fork the repository and create your branch from master
- If you've added code that should be tested, add tests!
- If you've changed APIs, update the documentation.
- Ensure the test suite passes (npm test).
- Make sure your code lints (npm run lint).
- Commit your changes (git commit) Commit Message Format Reference
Similar Projects
LICENSE
MIT
