refactor(schema): add comment schemas

pull/588/head
ppoffice 2019-12-24 14:16:42 -05:00
parent f1e22741df
commit 44b3603384
15 changed files with 509 additions and 18 deletions

View File

@ -1,7 +1,8 @@
{
"extends": [
"hexo",
"plugin:react/recommended"
"plugin:react/recommended",
"plugin:json/recommended"
],
"settings": {
"node": {

View File

@ -0,0 +1,25 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "/comment/changyan.json",
"description": "Changyan comment plugin configurations",
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "changyan"
},
"appid": {
"type": "string",
"description": "Changyan app ID"
},
"shortname": {
"type": "string",
"description": "Changyan configuration ID"
}
},
"required": [
"type",
"appid",
"conf"
]
}

View File

@ -0,0 +1,20 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "/comment/disqus.json",
"description": "Disqus comment plugin configurations",
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "disqus"
},
"shortname": {
"type": "string",
"description": "Disqus shortname"
}
},
"required": [
"type",
"shortname"
]
}

View File

@ -0,0 +1,55 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "/comment/disqusjs.json",
"description": "DisqusJS comment plugin configurations",
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "disqusjs"
},
"shortname": {
"type": "string",
"description": "Disqus shortname"
},
"apiKey": {
"description": "Disqus application API key",
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": [
{
"type": "string"
}
]
}
]
},
"api": {
"type": "string",
"description": "Disqus API endpoint"
},
"admin": {
"type": "string",
"description": "Disqus moderator username"
},
"adminLabel": {
"type": "string",
"description": "Disqus moderator badge text",
"default": false
},
"nesting": {
"type": "integer",
"description": "Maximum number of comment nesting level",
"default": 4
}
},
"required": [
"type",
"shortname",
"apiKey"
]
}

View File

@ -0,0 +1,15 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "/comment/facebook.json",
"description": "Facebook comment plugin configurations",
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "facebook"
}
},
"required": [
"type"
]
}

View File

@ -0,0 +1,76 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "/comment/gitalk.json",
"description": "Gitalk comment plugin configurations",
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "gitalk"
},
"clientId": {
"type": "string",
"description": "GitHub application client ID"
},
"clientSecret": {
"type": "string",
"description": "GitHub application client secret"
},
"repo": {
"type": "string",
"description": "GitHub repository"
},
"owner": {
"type": "string",
"description": "GitHub repository owner. Can be personal user or organization"
},
"admin": {
"type": "array",
"description": "GitHub repository owner and collaborators. (Users who having write access to this repository)",
"items": {
"type": "string"
}
},
"perPage": {
"type": "number",
"description": "Pagination size, with maximum 100",
"default": 10
},
"distractionFreeMode": {
"type": "boolean",
"description": "Facebook-like distraction free mode",
"default": false
},
"pagerDirection": {
"type": "string",
"description": "Comment sorting direction, available values are `last` and `first`",
"default": "last"
},
"createIssueManually": {
"type": "boolean",
"description": "Create GitHub issues manually for each page",
"default": false
},
"proxy": {
"type": "string",
"description": "GitHub oauth request reverse proxy for CORS"
},
"flipMoveOptions": {
"type": "object",
"description": "Comment list animation"
},
"enableHotKey": {
"type": "boolean",
"description": "Enable hot key (cmd|ctrl + enter) submit comment",
"default": true
}
},
"required": [
"type",
"clientId",
"clientSecret",
"repo",
"owner",
"admin"
]
}

View File

@ -0,0 +1,50 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "/comment/gitment.json",
"description": "Gitment comment plugin configurations",
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "gitment"
},
"owner": {
"type": "string",
"description": "Your GitHub ID"
},
"repo": {
"type": "string",
"description": "The repository to store your comments. Make sure you're repo's owner"
},
"clientId": {
"type": "string",
"description": "GitHub client ID"
},
"clientSecret": {
"type": "string",
"description": "GitHub client secret"
},
"theme": {
"type": "string",
"description": "An optional Gitment theme object",
"default": "gitment.defaultTheme"
},
"perPage": {
"type": "number",
"description": "An optional number to which comments will be paginated",
"default": 20
},
"maxCommentHeight": {
"type": "number",
"description": "An optional number to limit comments' max height, over which comments will be folded",
"default": 250
}
},
"required": [
"type",
"owner",
"repo",
"clientId",
"clientSecret"
]
}

View File

@ -0,0 +1,20 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "/comment/isso.json",
"description": "Isso comment plugin configurations",
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "isso"
},
"url": {
"type": "string",
"description": "URL to your Isso comment service"
}
},
"required": [
"type",
"url"
]
}

View File

@ -0,0 +1,20 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "/comment/livere.json",
"description": "Livere comment plugin configurations",
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "livere"
},
"url": {
"type": "string",
"description": "LiveRe comment service UID"
}
},
"required": [
"type",
"url"
]
}

View File

@ -0,0 +1,92 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "/comment/valine.json",
"description": "Valine comment plugin configurations",
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "valine"
},
"appId": {
"type": "string",
"description": "Application <APP_ID> from Leancloud"
},
"appKey": {
"type": "string",
"description": "Application <APP_KEY> from Leancloud"
},
"placeholder": {
"type": "string",
"description": "Comment box placeholders"
},
"notify": {
"type": "boolean",
"description": "Enable email notification when someone comments",
"default": false
},
"verify": {
"type": "boolean",
"description": "Enable verification code service",
"default": false
},
"avatar": {
"type": "string",
"description": "Gravatar type",
"enum": [
"",
"mp",
"identicon",
"monsterid",
"wavatar",
"robohash",
"retro",
"hide",
"mm"
],
"default": "mm"
},
"avatarForce": {
"type": "boolean",
"description": "Pull the latest avatar upon page visit",
"default": false
},
"meta": {
"type": "array",
"description": "Reviewer attributes",
"items": {
"type": "string"
},
"default": [
"nick",
"mail",
"link"
]
},
"pageSize": {
"type": "integer",
"description": "Number of comments per page",
"default": 10
},
"visitor": {
"type": "boolean",
"description": "Show visitor count",
"default": false
},
"highlight": {
"type": "boolean",
"description": "Enable code highlighting",
"default": true
},
"recordIP": {
"type": "boolean",
"description": "Record reviewer IP address",
"default": false
}
},
"required": [
"type",
"appId",
"appKey"
]
}

View File

@ -0,0 +1,68 @@
const { Component, Fragment } = require('inferno');
const { cacheComponent } = require('../util/cache');
class DisqusJs extends Component {
render() {
const {
shortname,
apiKey,
api,
admin,
adminLabel = false,
nesting = 4,
disqusId,
path,
permalink,
pageTitle,
siteTitle,
jsUrl,
cssUrl
} = this.props;
if (!shortname) {
return <div class="notification is-danger">
You forgot to set the <code>shortname</code> or <code>apiKey</code> for Disqus.
Please set it in <code>_config.yml</code>.
</div>;
}
const js = `new DisqusJS({
shortname: '${shortname}',
apikey: '${JSON.stringify(apiKey)}',
siteName: '${siteTitle}',
identifier: '${disqusId || path}',
url: '${permalink || path}',
title: '${pageTitle}',
api: '${api}',
admin: '${admin}',
adminLabel: '${adminLabel}',
nesting: ${nesting}%>
});`;
return <Fragment>
<link rel="stylesheet" href={cssUrl} />
<div id="disqus_thread">
<noscript>Please enable JavaScript to view the <a href="//disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</div>
<script src={jsUrl}></script>
<script dangerouslySetInnerHTML={{ __html: js }}></script>
</Fragment>;
}
}
module.exports = cacheComponent(DisqusJs, 'comment.disqusjs', props => {
const { config, page, helper, comment } = props;
return {
path: page.path,
shortname: comment.shortname,
apiKey: comment.apiKey,
api: comment.api,
admin: comment.admin,
adminLabel: comment.adminLabel,
nesting: comment.nesting,
disqusId: page.disqusId,
permalink: page.permalink,
pageTitle: page.title,
siteTitle: config.title,
jsUrl: helper.cdn('disqusjs', '1.2.5', 'dist/disqus.js'),
cssUrl: helper.cdn('disqusjs', '1.2.5', 'dist/disqusjs.css')
};
});

View File

@ -11,8 +11,13 @@ class Gitalk extends Component {
admin,
clientId,
clientSecret,
createIssueManually,
distractionFreeMode,
createIssueManually = false,
distractionFreeMode = false,
pagerDirection = 'last',
perPage = 10,
proxy,
flipMoveOptions,
enableHotKey,
jsUrl,
cssUrl
} = this.props;
@ -31,8 +36,13 @@ class Gitalk extends Component {
clientID: '${clientId}',
clientSecret: '${clientSecret}',
admin: ${JSON.stringify(admin)},
createIssueManually: ${createIssueManually || false},
distractionFreeMode: ${distractionFreeMode || false}
createIssueManually: ${createIssueManually},
distractionFreeMode: ${distractionFreeMode},
perPage: ${perPage},
pagerDirection: '${pagerDirection}',
${proxy ? `proxy: '${proxy}',` : ''}
${flipMoveOptions ? `flipMoveOptions: ${JSON.stringify(flipMoveOptions)},` : ''}
enableHotKey: ${enableHotKey ? !!enableHotKey : true}
})
gitalk.render('comment-container')`;
return <Fragment>
@ -58,6 +68,11 @@ module.exports = cacheComponent(Gitalk, 'comment.gitalk', props => {
clientSecret: comment.clientSecret,
createIssueManually: comment.createIssueManually,
distractionFreeMode: comment.distractionFreeMode,
pagerDirection: comment.pagerDirection,
perPage: comment.perPage,
proxy: comment.proxy,
flipMoveOptions: comment.flipMoveOptions,
enableHotKey: comment.enableHotKey,
cssUrl: helper.cdn('gitalk', '1.4.1', 'dist/gitalk.css'),
jsUrl: helper.cdn('gitalk', '1.4.1', 'dist/gitalk.min.js')
};

View File

@ -9,13 +9,15 @@ class Gitment extends Component {
repo,
owner,
clientId,
clientSecret
clientSecret,
perPage = 20,
maxCommentHeight = 250
} = this.props;
if (!id || !repo || !owner || !clientId || !clientSecret) {
return <div class="notification is-danger">
You forgot to set the <code>owner</code>, <code>repo</code>, <code>client_id</code>,
or <code>client_secret</code> for Gitment.
You forgot to set the <code>owner</code>, <code>repo</code>, <code>clientId</code>,
or <code>clientSecret</code> for Gitment.
Please set it in <code>_config.yml</code>.
</div>;
}
@ -27,6 +29,8 @@ class Gitment extends Component {
client_id: '${clientId}',
client_secret: '${clientSecret}',
},
perPage: ${perPage},
maxCommentHeight: ${maxCommentHeight}
})
gitment.render('comment-container')`;
return <Fragment>
@ -46,7 +50,9 @@ module.exports = cacheComponent(Gitment, 'comment.gitment', props => {
id,
repo: comment.repo,
owner: comment.owner,
clientId: comment.client_id,
clientSecret: comment.client_secret
clientId: comment.clientId,
clientSecret: comment.clientSecret,
perPage: comment.perPage,
maxCommentHeight: comment.maxCommentHeight
};
});

View File

@ -3,7 +3,20 @@ const { cacheComponent } = require('../util/cache');
class Valine extends Component {
render() {
const { appId, appKey, notify, verify, placeholder } = this.props;
const {
appId,
appKey,
notify,
verify,
placeholder,
avatar = 'mm',
avatarForce = false,
meta = ['nick', 'mail', 'link'],
pageSize = 10,
visitor = false,
highlight = true,
recordIP = false
} = this.props;
if (!appId || !appKey) {
return <div class="notification is-danger">
You forgot to set the <code>app_id</code> or <code>app_key</code> for Valine.
@ -14,9 +27,16 @@ class Valine extends Component {
el: '#valine-thread' ,
notify: ${notify},
verify: ${verify},
app_id: '${appId}',
app_key: '${appKey}',
placeholder: '${placeholder}'
appId: '${appId}',
appKey: '${appKey}',
placeholder: '${placeholder}',
avatar: '${avatar}',
avatarForce: ${avatarForce},
meta: ${JSON.stringify(meta)},
pageSize: ${pageSize},
visitor: ${visitor},
highlight: ${highlight},
recordIP: ${recordIP}
});`;
return <Fragment>
<div id="valine-thread" class="content"></div>
@ -35,6 +55,13 @@ module.exports = cacheComponent(Valine, 'comment.valine', props => {
appKey: comment.app_key,
notify: comment.notify,
verify: comment.verify,
placeholder: comment.placeholder
placeholder: comment.placeholder,
avatar: comment.avatar,
avatarForce: comment.avatarForce,
meta: comment.meta,
pageSize: comment.pageSize,
visitor: comment.visitor,
highlight: comment.highlight,
recordIP: comment.recordIP
};
});

View File

@ -10,7 +10,7 @@
"author": "ppoffice <zrp1994@gmail.com>",
"license": "MIT",
"scripts": {
"lint": "eslint --ext .js --ext .jsx .",
"lint": "eslint --ext .js --ext .jsx --ext .json .",
"test": "mocha test/index.js",
"postpublish": "PACKAGE_VERSION=$(cat package.json | grep \\\"version\\\" | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') && git tag $PACKAGE_VERSION && git push --tags"
},
@ -18,17 +18,18 @@
"chai": "^4.2.0",
"eslint": "^6.8.0",
"eslint-config-hexo": "^4.1.0",
"eslint-plugin-json": "^2.0.1",
"eslint-plugin-react": "^7.17.0",
"mocha": "^6.2.2"
},
"peerDependencies": {
"hexo": "^4.0.0",
"hexo-util": "^1.8.0",
"hexo-log": "^1.0.0",
"hexo-pagination": "^1.0.0",
"hexo-renderer-inferno": "^0.1.1",
"hexo-util": "^1.8.0",
"inferno": "^7.3.3",
"inferno-create-element": "^7.3.3",
"moment": "^2.22.2"
}
}
}