2019-12-22 03:43:39 +00:00
|
|
|
const crypto = require('crypto');
|
|
|
|
const { Component, Fragment } = require('inferno');
|
|
|
|
const { cacheComponent } = require('../util/cache');
|
|
|
|
|
|
|
|
class Gitalk extends Component {
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
id,
|
|
|
|
repo,
|
|
|
|
owner,
|
|
|
|
admin,
|
|
|
|
clientId,
|
|
|
|
clientSecret,
|
|
|
|
createIssueManually,
|
|
|
|
distractionFreeMode,
|
2019-12-22 17:38:31 +00:00
|
|
|
jsUrl,
|
|
|
|
cssUrl
|
2019-12-22 03:43:39 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
if (!id || !repo || !owner || !admin || !clientId || !clientSecret) {
|
2019-12-24 05:36:39 +00:00
|
|
|
return <div class="notification is-danger">
|
2019-12-22 03:43:39 +00:00
|
|
|
You forgot to set the <code>owner</code>, <code>admin</code>, <code>repo</code>,
|
2019-12-24 16:12:08 +00:00
|
|
|
<code>clientId</code>, or <code>clientSecret</code> for Gittalk.
|
2019-12-22 03:43:39 +00:00
|
|
|
Please set it in <code>_config.yml</code>.
|
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
const js = `var gitalk = new Gitalk({
|
|
|
|
id: '${id}',
|
|
|
|
repo: '${repo}',
|
|
|
|
owner: '${owner}',
|
|
|
|
clientID: '${clientId}',
|
|
|
|
clientSecret: '${clientSecret}',
|
|
|
|
admin: ${JSON.stringify(admin)},
|
|
|
|
createIssueManually: ${createIssueManually || false},
|
|
|
|
distractionFreeMode: ${distractionFreeMode || false}
|
|
|
|
})
|
|
|
|
gitalk.render('comment-container')`;
|
|
|
|
return <Fragment>
|
|
|
|
<div id="comment-container"></div>
|
2019-12-22 17:38:31 +00:00
|
|
|
<link rel="stylesheet" href={cssUrl} />
|
|
|
|
<script src={jsUrl}></script>
|
2019-12-22 03:43:39 +00:00
|
|
|
<script dangerouslySetInnerHTML={{ __html: js }}></script>
|
|
|
|
</Fragment>;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = cacheComponent(Gitalk, 'comment.gitalk', props => {
|
2019-12-23 21:18:59 +00:00
|
|
|
const { helper, comment } = props;
|
|
|
|
|
2019-12-22 03:43:39 +00:00
|
|
|
// FIXME: config name change
|
|
|
|
const id = crypto.createHash('md5').update(props.page.path).digest('hex');
|
|
|
|
return {
|
|
|
|
id,
|
2019-12-23 21:18:59 +00:00
|
|
|
repo: comment.repo,
|
|
|
|
owner: comment.owner,
|
|
|
|
admin: comment.admin,
|
|
|
|
clientId: comment.clientId,
|
|
|
|
clientSecret: comment.clientSecret,
|
|
|
|
createIssueManually: comment.createIssueManually,
|
|
|
|
distractionFreeMode: comment.distractionFreeMode,
|
|
|
|
cssUrl: helper.cdn('gitalk', '1.4.1', 'dist/gitalk.css'),
|
|
|
|
jsUrl: helper.cdn('gitalk', '1.4.1', 'dist/gitalk.min.js')
|
2019-12-22 03:43:39 +00:00
|
|
|
};
|
|
|
|
});
|