2019-12-22 03:43:39 +00:00
|
|
|
const { Component, Fragment } = require('inferno');
|
|
|
|
const { cacheComponent } = require('../util/cache');
|
|
|
|
|
|
|
|
class Disqus extends Component {
|
|
|
|
render() {
|
|
|
|
const { shortname, disqusId, path, permalink } = this.props;
|
|
|
|
if (!shortname) {
|
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>shortname</code> for Disqus.
|
|
|
|
Please set it in <code>_config.yml</code>.
|
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
const js = `var disqus_config = function () {
|
|
|
|
this.page.url = '${permalink}';
|
|
|
|
this.page.identifier = '${disqusId || path}';
|
|
|
|
};
|
|
|
|
(function() {
|
|
|
|
var d = document, s = d.createElement('script');
|
|
|
|
s.src = '//' + '${shortname}' + '.disqus.com/embed.js';
|
|
|
|
s.setAttribute('data-timestamp', +new Date());
|
|
|
|
(d.head || d.body).appendChild(s);
|
|
|
|
})();`;
|
|
|
|
return <Fragment>
|
|
|
|
<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 dangerouslySetInnerHTML={{ __html: js }}></script>
|
|
|
|
</Fragment>;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = cacheComponent(Disqus, 'comment.disqus', props => {
|
2019-12-23 21:18:59 +00:00
|
|
|
const { comment, page } = props;
|
|
|
|
|
2019-12-22 03:43:39 +00:00
|
|
|
return {
|
2019-12-23 21:18:59 +00:00
|
|
|
path: page.path,
|
|
|
|
shortname: comment.shortname,
|
|
|
|
disqusId: page.disqusId,
|
|
|
|
permalink: page.permalink
|
2019-12-22 03:43:39 +00:00
|
|
|
};
|
|
|
|
});
|