hexo-component-inferno 4.0.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +159 -8
  3. package/asset/js/algolia.js +27 -10
  4. package/asset/js/insight.js +62 -44
  5. package/lib/core/migrate.js +23 -4
  6. package/lib/core/schema.js +31 -9
  7. package/lib/core/view.js +1 -1
  8. package/lib/hexo/filter/locals.js +5 -2
  9. package/lib/hexo/generator/category.js +8 -1
  10. package/lib/hexo/generator/insight.js +8 -15
  11. package/lib/hexo/generator/manifest.js +6 -0
  12. package/lib/hexo/helper/cdn.js +11 -3
  13. package/lib/hexo/tag/message.js +11 -1
  14. package/lib/hexo/tag/tabs.js +28 -5
  15. package/lib/schema/comment/artalk.json +37 -0
  16. package/lib/schema/comment/beaudar.json +62 -0
  17. package/lib/schema/comment/cusdis.json +34 -0
  18. package/lib/schema/comment/giscus.json +12 -1
  19. package/lib/schema/comment/gitment.json +1 -1
  20. package/lib/schema/comment/utterances.json +15 -1
  21. package/lib/schema/comment/valine.json +1 -1
  22. package/lib/schema/comment/waline.json +2 -2
  23. package/lib/schema/misc/open_graph.json +0 -1
  24. package/lib/schema/plugin/waline_pageview.json +14 -0
  25. package/lib/schema/share/addthis.json +1 -1
  26. package/lib/schema/widget/archives.json +28 -0
  27. package/lib/schema/widget/categories.json +32 -0
  28. package/lib/schema/widget/recent_posts.json +5 -0
  29. package/lib/schema/widget/subscribe_email.json +1 -1
  30. package/lib/schema/widget/tags.json +1 -1
  31. package/lib/util/appearance.js +40 -0
  32. package/lib/util/classname.js +1 -1
  33. package/lib/util/deprecate.js +28 -0
  34. package/lib/util/html.js +51 -0
  35. package/lib/util/i18n.js +24 -0
  36. package/lib/util/script.js +73 -5
  37. package/lib/view/comment/artalk.js +119 -0
  38. package/lib/view/comment/beaudar.js +134 -0
  39. package/lib/view/comment/changyan.js +2 -1
  40. package/lib/view/comment/cusdis.js +120 -0
  41. package/lib/view/comment/disqus.js +3 -1
  42. package/lib/view/comment/disqusjs.js +3 -2
  43. package/lib/view/comment/facebook.js +3 -1
  44. package/lib/view/comment/giscus.js +32 -21
  45. package/lib/view/comment/gitalk.js +4 -2
  46. package/lib/view/comment/gitment.js +7 -2
  47. package/lib/view/comment/isso.js +5 -1
  48. package/lib/view/comment/twikoo.js +5 -1
  49. package/lib/view/comment/utterances.js +26 -16
  50. package/lib/view/comment/valine.js +7 -1
  51. package/lib/view/comment/waline.js +31 -21
  52. package/lib/view/donate/afdian.js +1 -1
  53. package/lib/view/donate/alipay.js +1 -1
  54. package/lib/view/donate/buymeacoffee.js +1 -1
  55. package/lib/view/donate/patreon.js +1 -1
  56. package/lib/view/donate/wechat.js +1 -1
  57. package/lib/view/misc/meta.js +9 -3
  58. package/lib/view/misc/open_graph.js +12 -15
  59. package/lib/view/misc/structured_data.js +8 -9
  60. package/lib/view/misc/web_app.js +15 -6
  61. package/lib/view/plugin/baidu_analytics.js +3 -1
  62. package/lib/view/plugin/cookie_consent.js +3 -1
  63. package/lib/view/plugin/google_analytics.js +3 -1
  64. package/lib/view/plugin/hotjar.js +3 -1
  65. package/lib/view/plugin/matomo.js +3 -1
  66. package/lib/view/plugin/outdated_browser.js +1 -1
  67. package/lib/view/plugin/statcounter.js +3 -1
  68. package/lib/view/plugin/twitter_conversion_tracking.js +3 -1
  69. package/lib/view/plugin/waline_pageview.js +100 -0
  70. package/lib/view/search/algolia.js +3 -1
  71. package/lib/view/search/baidu.js +3 -1
  72. package/lib/view/search/google_cse.js +3 -1
  73. package/lib/view/search/insight.js +4 -2
  74. package/lib/view/share/addthis.js +4 -0
  75. package/lib/view/widget/archives.js +37 -9
  76. package/lib/view/widget/categories.js +41 -15
  77. package/lib/view/widget/links.js +1 -1
  78. package/lib/view/widget/subscribe_email.js +5 -0
  79. package/lib/view/widget/tags.js +18 -5
  80. package/package.json +4 -2
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Utility functions for translations.
3
+ * @module util/i18n
4
+ */
5
+
6
+ /**
7
+ * Translate a key with the <code>__</code> helper of Hexo, or use the fallback text when the theme has
8
+ * no translation for the key, in which case Hexo returns the key itself.
9
+ *
10
+ * @param {Function} __ The <code>__</code> helper function of Hexo.
11
+ * @param {string} key The translation key.
12
+ * @param {string} fallback The text to use without a translation.
13
+ * @returns {string} The translated text.
14
+ *
15
+ * @example
16
+ * translate(helper.__, 'widget.more', 'More');
17
+ */
18
+ function translate(__, key, fallback) {
19
+ const text = typeof __ === 'function' ? __(key) : null;
20
+ return text && text !== key ? text : fallback;
21
+ }
22
+ module.exports = {
23
+ translate
24
+ };
@@ -1,8 +1,25 @@
1
1
  /**
2
- * A utility function for building inline scripts that load external scripts without blocking the page.
2
+ * Utility functions for building inline scripts that load external scripts without blocking the page.
3
3
  * @module util/script
4
4
  */
5
5
 
6
+ /**
7
+ * Convert a value to JavaScript code that can be put in an inline <code>&lt;script&gt;</code>.
8
+ * <p>
9
+ * Unlike <code>JSON.stringify</code> alone, it escapes <code>&lt;</code>, so that a value containing
10
+ * <code>&lt;/script&gt;</code>, such as a page title, cannot end the inline script, and the line
11
+ * separators U+2028 and U+2029, which older browsers do not allow in JavaScript strings.
12
+ *
13
+ * @param {any} value A value that can be converted to JSON.
14
+ * @returns {string} The JavaScript code.
15
+ *
16
+ * @example
17
+ * toJs('</script>'); // '"\\u003c/script>"'
18
+ */
19
+ function toJs(value) {
20
+ return JSON.stringify(value).replace(/</g, '\\u003c').replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029');
21
+ }
22
+
6
23
  /**
7
24
  * Build an inline script that loads external scripts asynchronously and in order, and then runs the
8
25
  * given code.
@@ -20,10 +37,10 @@
20
37
  * @example
21
38
  * <script dangerouslySetInnerHTML={{ __html: loadScripts('/path/to/lib.js', 'lib.init();') }} />
22
39
  */
23
- module.exports = function (urls, code, attrs = {}) {
40
+ function loadScripts(urls, code, attrs = {}) {
24
41
  return `(function () {
25
- var urls = ${JSON.stringify([].concat(urls))};
26
- var attrs = ${JSON.stringify(attrs)};
42
+ var urls = ${toJs([].concat(urls))};
43
+ var attrs = ${toJs(attrs)};
27
44
  function run() {
28
45
  ${code}
29
46
  }
@@ -54,6 +71,11 @@ module.exports = function (urls, code, attrs = {}) {
54
71
  script.addEventListener('load', function () {
55
72
  this.setAttribute('data-loaded', 'true');
56
73
  });
74
+ // Remove a script that fails to load, so that the next run, e.g., after a PJAX page switch,
75
+ // adds it again instead of waiting for it
76
+ script.addEventListener('error', function () {
77
+ this.remove();
78
+ });
57
79
  document.head.appendChild(script);
58
80
  }
59
81
  script.addEventListener('load', function () {
@@ -62,4 +84,50 @@ module.exports = function (urls, code, attrs = {}) {
62
84
  }
63
85
  load(0);
64
86
  })();`;
65
- };
87
+ }
88
+
89
+ /**
90
+ * Build an inline script that adds an external script to an element, for example the client script of
91
+ * a comment system that reads its options from the attributes of its own <code>&lt;script&gt;</code>
92
+ * tag.
93
+ * <p>
94
+ * The external script is added every time the inline script runs. Unlike a <code>&lt;script&gt;</code>
95
+ * tag in the page, which PJAX runs again without its attributes and outside of its element, it keeps
96
+ * its attributes and stays in the element. It is added after the inline script has finished, so that
97
+ * PJAX, which runs the scripts of the new page right after switching to it, does not run it again.
98
+ *
99
+ * @param {string} selector CSS selector of the element to add the external script to.
100
+ * @param {string} url URL of the external script.
101
+ * @param {Object} attrs Attributes to set on the external script element.
102
+ * @param {Object} [dynamicAttrs] More attributes, whose values are JavaScript expressions evaluated by
103
+ * the inline script, for example to choose a theme in the browser.
104
+ * @returns {string} The inline JavaScript code.
105
+ *
106
+ * @example
107
+ * appendScript('#comments-thread', 'https://comments.example.com/client.js', { repo: 'user/repo' }, {
108
+ * theme: "window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'",
109
+ * });
110
+ */
111
+ function appendScript(selector, url, attrs, dynamicAttrs = {}) {
112
+ const dynamic = Object.keys(dynamicAttrs).map(name => `attrs[${toJs(name)}] = ${dynamicAttrs[name]};`).join('\n ');
113
+ return `(function () {
114
+ var element = document.querySelector(${toJs(selector)});
115
+ if (!element) {
116
+ return;
117
+ }
118
+ var attrs = ${toJs(attrs)};
119
+ ${dynamic}
120
+ var script = document.createElement('script');
121
+ for (var name in attrs) {
122
+ script.setAttribute(name, attrs[name]);
123
+ }
124
+ script.src = ${toJs(url)};
125
+ script.async = true;
126
+ setTimeout(function () {
127
+ element.appendChild(script);
128
+ });
129
+ })();`;
130
+ }
131
+ module.exports = loadScripts;
132
+ module.exports.appendScript = appendScript;
133
+ module.exports.toJs = toJs;
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ var _inferno = require("inferno");
5
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
6
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
7
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
8
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
9
+ function _toPrimitive(t, e) { if ("object" != _typeof(t) || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
10
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
11
+ function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
12
+ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
13
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
14
+ function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
15
+ function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
16
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
17
+ /**
18
+ * Artalk comment JSX component.
19
+ * @module view/comment/artalk
20
+ */
21
+ var _require = require('inferno'),
22
+ Component = _require.Component;
23
+ var _require2 = require('../../util/cache'),
24
+ cacheComponent = _require2.cacheComponent;
25
+ var loadScripts = require('../../util/script');
26
+ var toJs = loadScripts.toJs;
27
+ var _require3 = require('../../util/appearance'),
28
+ getAppearance = _require3.getAppearance,
29
+ isDark = _require3.isDark;
30
+
31
+ /**
32
+ * Artalk comment JSX component.
33
+ *
34
+ * @see https://artalk.js.org/guide/frontend/config.html
35
+ * @example
36
+ * <Artalk
37
+ * server="https://artalk.example.com"
38
+ * site="******"
39
+ * pageKey="/path/to/page/"
40
+ * pageTitle="******"
41
+ * locale="en"
42
+ * darkMode={false}
43
+ * jsUrl="/path/to/Artalk.js"
44
+ * cssUrl="/path/to/Artalk.css" />
45
+ */
46
+ var Artalk = /*#__PURE__*/function (_Component) {
47
+ function Artalk() {
48
+ _classCallCheck(this, Artalk);
49
+ return _callSuper(this, Artalk, arguments);
50
+ }
51
+ _inherits(Artalk, _Component);
52
+ return _createClass(Artalk, [{
53
+ key: "render",
54
+ value: function render() {
55
+ var _this$props = this.props,
56
+ server = _this$props.server,
57
+ site = _this$props.site,
58
+ pageKey = _this$props.pageKey,
59
+ pageTitle = _this$props.pageTitle,
60
+ locale = _this$props.locale,
61
+ darkMode = _this$props.darkMode,
62
+ jsUrl = _this$props.jsUrl,
63
+ cssUrl = _this$props.cssUrl;
64
+ if (!server) {
65
+ return (0, _inferno.createVNode)(1, "div", "notification is-danger", [(0, _inferno.createTextVNode)("You forgot to set the "), (0, _inferno.createVNode)(1, "code", null, "server", 16), (0, _inferno.createTextVNode)(" for Artalk. Please set it in"), (0, _inferno.createTextVNode)(' '), (0, _inferno.createVNode)(1, "code", null, "_config.yml", 16), (0, _inferno.createTextVNode)(".")], 0);
66
+ }
67
+ // Without the dark_mode option, follow the appearance of the page
68
+ var darkModeOption = darkMode === null || typeof darkMode === 'undefined' ? "".concat(getAppearance(), " === 'auto' ? 'auto' : ").concat(isDark()) : toJs(darkMode);
69
+ // PJAX replaces the element of the previous instance, so destroy it before initializing again
70
+ var js = "if (window.__artalkInstance) {\n window.__artalkInstance.destroy();\n }\n window.__artalkInstance = Artalk.init({\n el: '#artalk-thread',\n server: ".concat(toJs(server), ",\n ").concat(site ? "site: ".concat(toJs(site), ",") : '', "\n ").concat(pageKey ? "pageKey: ".concat(toJs(pageKey), ",") : '', "\n ").concat(pageTitle ? "pageTitle: ".concat(toJs(pageTitle), ",") : '', "\n ").concat(locale ? "locale: ".concat(toJs(locale), ",") : '', "\n darkMode: ").concat(darkModeOption, ",\n });");
71
+ return (0, _inferno.createFragment)([(0, _inferno.createVNode)(1, "div", null, null, 1, {
72
+ "id": "artalk-thread"
73
+ }), (0, _inferno.createVNode)(1, "link", null, null, 1, {
74
+ "rel": "stylesheet",
75
+ "href": cssUrl,
76
+ "media": "print",
77
+ "onload": "this.media='all'"
78
+ }), (0, _inferno.createVNode)(1, "script", null, null, 1, {
79
+ "dangerouslySetInnerHTML": {
80
+ __html: loadScripts(jsUrl, js)
81
+ }
82
+ })], 4);
83
+ }
84
+ }]);
85
+ }(Component);
86
+ /**
87
+ * Cacheable Artalk comment JSX component.
88
+ * <p>
89
+ * This class is supposed to be used in combination with the <code>locals</code> hexo filter
90
+ * ({@link module:hexo/filter/locals}).
91
+ *
92
+ * @see module:util/cache.cacheComponent
93
+ * @example
94
+ * <Artalk.Cacheable
95
+ * comment={{
96
+ * server: "https://artalk.example.com",
97
+ * site: "******",
98
+ * locale: "en",
99
+ * dark_mode: false
100
+ * }}
101
+ * page={{ title: "******" }}
102
+ * helper={{ cdn: function() {...} }} />
103
+ */
104
+ Artalk.Cacheable = cacheComponent(Artalk, 'comment.artalk', function (props) {
105
+ var comment = props.comment,
106
+ helper = props.helper,
107
+ page = props.page;
108
+ return {
109
+ server: comment.server,
110
+ site: comment.site,
111
+ pageKey: comment.page_key,
112
+ pageTitle: page.title,
113
+ locale: comment.locale,
114
+ darkMode: comment.dark_mode,
115
+ jsUrl: helper.cdn('artalk', '2.9.1', 'dist/Artalk.js'),
116
+ cssUrl: helper.cdn('artalk', '2.9.1', 'dist/Artalk.css')
117
+ };
118
+ });
119
+ module.exports = Artalk;
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ var _inferno = require("inferno");
5
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
6
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
7
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
8
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
9
+ function _toPrimitive(t, e) { if ("object" != _typeof(t) || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
10
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
11
+ function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
12
+ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
13
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
14
+ function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
15
+ function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
16
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
17
+ /**
18
+ * Beaudar comment JSX component.
19
+ * @module view/comment/beaudar
20
+ */
21
+ var _require = require('inferno'),
22
+ Component = _require.Component;
23
+ var _require2 = require('../../util/cache'),
24
+ cacheComponent = _require2.cacheComponent;
25
+ var _require3 = require('../../util/script'),
26
+ appendScript = _require3.appendScript,
27
+ toJs = _require3.toJs;
28
+ var _require4 = require('../../util/appearance'),
29
+ isDark = _require4.isDark;
30
+
31
+ /**
32
+ * Beaudar comment JSX component.
33
+ * <p>
34
+ * Beaudar is a Chinese fork of Utterances that keeps comments in GitHub issues.
35
+ *
36
+ * @see https://github.com/beaudar/beaudar
37
+ * @example
38
+ * <Beaudar
39
+ * repo="******"
40
+ * branch="main"
41
+ * issueTerm="******"
42
+ * issueNumber={123}
43
+ * label="******"
44
+ * theme="******"
45
+ * darkTheme="******" />
46
+ */
47
+ var Beaudar = /*#__PURE__*/function (_Component) {
48
+ function Beaudar() {
49
+ _classCallCheck(this, Beaudar);
50
+ return _callSuper(this, Beaudar, arguments);
51
+ }
52
+ _inherits(Beaudar, _Component);
53
+ return _createClass(Beaudar, [{
54
+ key: "render",
55
+ value: function render() {
56
+ var _this$props = this.props,
57
+ repo = _this$props.repo,
58
+ branch = _this$props.branch,
59
+ issueTerm = _this$props.issueTerm,
60
+ issueNumber = _this$props.issueNumber,
61
+ label = _this$props.label,
62
+ theme = _this$props.theme,
63
+ darkTheme = _this$props.darkTheme;
64
+ if (!repo || !issueTerm && !issueNumber) {
65
+ return (0, _inferno.createVNode)(1, "div", "notification is-danger", [(0, _inferno.createTextVNode)("You forgot to set the "), (0, _inferno.createVNode)(1, "code", null, "repo", 16), (0, _inferno.createTextVNode)(", "), (0, _inferno.createVNode)(1, "code", null, "issue_term", 16), (0, _inferno.createTextVNode)(", or"), (0, _inferno.createTextVNode)(' '), (0, _inferno.createVNode)(1, "code", null, "issue_number", 16), (0, _inferno.createTextVNode)(" for Beaudar. Please set it in "), (0, _inferno.createVNode)(1, "code", null, "_config.yml", 16), (0, _inferno.createTextVNode)(".")], 0);
66
+ }
67
+ var config = {
68
+ repo: repo
69
+ };
70
+ if (branch) {
71
+ config.branch = branch;
72
+ }
73
+ if (issueTerm) {
74
+ config['issue-term'] = issueTerm;
75
+ } else {
76
+ config['issue-number'] = issueNumber;
77
+ }
78
+ if (label) {
79
+ config.label = label;
80
+ }
81
+ config.crossorigin = 'anonymous';
82
+ // Use the dark theme when the page looks dark
83
+ var js = appendScript('#beaudar-thread', 'https://beaudar.lipk.org/client.js', config, {
84
+ theme: "".concat(isDark(), " ? ").concat(toJs(darkTheme || 'github-dark'), " : ").concat(toJs(theme || 'github-light'))
85
+ });
86
+ return (0, _inferno.createFragment)([(0, _inferno.createVNode)(1, "div", null, null, 1, {
87
+ "id": "beaudar-thread"
88
+ }), (0, _inferno.createVNode)(1, "script", null, null, 1, {
89
+ "dangerouslySetInnerHTML": {
90
+ __html: js
91
+ }
92
+ })], 4);
93
+ }
94
+ }]);
95
+ }(Component);
96
+ /**
97
+ * Cacheable Beaudar comment JSX component.
98
+ * <p>
99
+ * This class is supposed to be used in combination with the <code>locals</code> hexo filter
100
+ * ({@link module:hexo/filter/locals}).
101
+ *
102
+ * @see module:util/cache.cacheComponent
103
+ * @example
104
+ * <Beaudar.Cacheable
105
+ * comment={{
106
+ * repo: "******",
107
+ * branch: "main",
108
+ * issue_term: "******",
109
+ * issue_number: {123},
110
+ * label: "******",
111
+ * theme: "******",
112
+ * dark_theme: "******"
113
+ * }} />
114
+ */
115
+ Beaudar.Cacheable = cacheComponent(Beaudar, 'comment.beaudar', function (props) {
116
+ var _props$comment = props.comment,
117
+ repo = _props$comment.repo,
118
+ branch = _props$comment.branch,
119
+ issue_term = _props$comment.issue_term,
120
+ issue_number = _props$comment.issue_number,
121
+ label = _props$comment.label,
122
+ theme = _props$comment.theme,
123
+ dark_theme = _props$comment.dark_theme;
124
+ return {
125
+ repo: repo,
126
+ branch: branch,
127
+ issueTerm: issue_term,
128
+ issueNumber: issue_number,
129
+ label: label,
130
+ theme: theme,
131
+ darkTheme: dark_theme
132
+ };
133
+ });
134
+ module.exports = Beaudar;
@@ -23,6 +23,7 @@ var _require = require('inferno'),
23
23
  var _require2 = require('../../util/cache'),
24
24
  cacheComponent = _require2.cacheComponent;
25
25
  var loadScripts = require('../../util/script');
26
+ var toJs = loadScripts.toJs;
26
27
 
27
28
  /**
28
29
  * ChangYan comment JSX component.
@@ -50,7 +51,7 @@ var ChangYan = /*#__PURE__*/function (_Component) {
50
51
  if (!appId || !conf) {
51
52
  return (0, _inferno.createVNode)(1, "div", "notification is-danger", [(0, _inferno.createTextVNode)("You forgot to set the "), (0, _inferno.createVNode)(1, "code", null, "app_id", 16), (0, _inferno.createTextVNode)(" or "), (0, _inferno.createVNode)(1, "code", null, "conf", 16), (0, _inferno.createTextVNode)(" for Changyan. Please set it in "), (0, _inferno.createVNode)(1, "code", null, "_config.yml", 16), (0, _inferno.createTextVNode)(".")], 4);
52
53
  }
53
- var js = "window.changyan.api.config({appid: '".concat(appId, "',conf: '").concat(conf, "'});");
54
+ var js = "window.changyan.api.config({appid: ".concat(toJs(appId), ",conf: ").concat(toJs(conf), "});");
54
55
  /* eslint-disable react/no-unknown-property */
55
56
  return (0, _inferno.createFragment)([(0, _inferno.createVNode)(1, "div", null, null, 1, {
56
57
  "id": "SOHUCS",
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ var _inferno = require("inferno");
5
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
6
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
7
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
8
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
9
+ function _toPrimitive(t, e) { if ("object" != _typeof(t) || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
10
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
11
+ function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
12
+ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
13
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
14
+ function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
15
+ function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
16
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
17
+ /**
18
+ * Cusdis comment JSX component.
19
+ * @module view/comment/cusdis
20
+ */
21
+ var _require = require('inferno'),
22
+ Component = _require.Component;
23
+ var _require2 = require('../../util/cache'),
24
+ cacheComponent = _require2.cacheComponent;
25
+ var loadScripts = require('../../util/script');
26
+ var toJs = loadScripts.toJs;
27
+ var _require3 = require('../../util/appearance'),
28
+ getAppearance = _require3.getAppearance;
29
+
30
+ /**
31
+ * Cusdis comment JSX component.
32
+ *
33
+ * @see https://cusdis.com/doc
34
+ * @example
35
+ * <Cusdis
36
+ * host="https://cusdis.com"
37
+ * appId="******"
38
+ * pageId="/path/to/page/"
39
+ * pageUrl="https://example.com/path/to/page/"
40
+ * pageTitle="******"
41
+ * theme="auto"
42
+ * lang="zh-cn" />
43
+ */
44
+ var Cusdis = /*#__PURE__*/function (_Component) {
45
+ function Cusdis() {
46
+ _classCallCheck(this, Cusdis);
47
+ return _callSuper(this, Cusdis, arguments);
48
+ }
49
+ _inherits(Cusdis, _Component);
50
+ return _createClass(Cusdis, [{
51
+ key: "render",
52
+ value: function render() {
53
+ var _this$props = this.props,
54
+ _this$props$host = _this$props.host,
55
+ host = _this$props$host === void 0 ? 'https://cusdis.com' : _this$props$host,
56
+ appId = _this$props.appId,
57
+ pageId = _this$props.pageId,
58
+ pageUrl = _this$props.pageUrl,
59
+ pageTitle = _this$props.pageTitle,
60
+ theme = _this$props.theme,
61
+ lang = _this$props.lang;
62
+ if (!appId) {
63
+ return (0, _inferno.createVNode)(1, "div", "notification is-danger", [(0, _inferno.createTextVNode)("You forgot to set the "), (0, _inferno.createVNode)(1, "code", null, "app_id", 16), (0, _inferno.createTextVNode)(" for Cusdis. Please set it in"), (0, _inferno.createTextVNode)(' '), (0, _inferno.createVNode)(1, "code", null, "_config.yml", 16), (0, _inferno.createTextVNode)(".")], 0);
64
+ }
65
+ var urls = ["".concat(host, "/js/cusdis.es.js")];
66
+ if (lang) {
67
+ urls.unshift("".concat(host, "/js/widget/lang/").concat(lang, ".js"));
68
+ }
69
+ // Without the theme option, follow the appearance of the page (light, dark, or auto, the same values
70
+ // as the themes of Cusdis). The Cusdis script renders #cusdis_thread when it loads, so render it
71
+ // directly only when the script is already loaded, e.g., when PJAX runs this code again.
72
+ var js = "(function () {\n var element = document.getElementById('cusdis_thread');\n if (!element) {\n return;\n }\n element.setAttribute('data-theme', ".concat(theme ? toJs(theme) : getAppearance(), ");\n if (window.renderCusdis) {\n window.renderCusdis(element);\n return;\n }\n ").concat(loadScripts(urls, ''), "\n })();");
73
+ return (0, _inferno.createFragment)([(0, _inferno.createVNode)(1, "div", null, null, 1, {
74
+ "id": "cusdis_thread",
75
+ "data-host": host,
76
+ "data-app-id": appId,
77
+ "data-page-id": pageId,
78
+ "data-page-url": pageUrl,
79
+ "data-page-title": pageTitle
80
+ }), (0, _inferno.createVNode)(1, "script", null, null, 1, {
81
+ "dangerouslySetInnerHTML": {
82
+ __html: js
83
+ }
84
+ })], 4);
85
+ }
86
+ }]);
87
+ }(Component);
88
+ /**
89
+ * Cacheable Cusdis comment JSX component.
90
+ * <p>
91
+ * This class is supposed to be used in combination with the <code>locals</code> hexo filter
92
+ * ({@link module:hexo/filter/locals}).
93
+ *
94
+ * @see module:util/cache.cacheComponent
95
+ * @example
96
+ * <Cusdis.Cacheable
97
+ * comment={{
98
+ * host: "https://cusdis.com",
99
+ * app_id: "******",
100
+ * theme: "auto",
101
+ * lang: "zh-cn"
102
+ * }}
103
+ * page={{ path: "/path/to/page/", permalink: "******", title: "******" }}
104
+ * helper={{ url_for: function() {...} }} />
105
+ */
106
+ Cusdis.Cacheable = cacheComponent(Cusdis, 'comment.cusdis', function (props) {
107
+ var comment = props.comment,
108
+ helper = props.helper,
109
+ page = props.page;
110
+ return {
111
+ host: comment.host ? comment.host.replace(/\/+$/, '') : undefined,
112
+ appId: comment.app_id,
113
+ pageId: helper.url_for(page.path),
114
+ pageUrl: page.permalink,
115
+ pageTitle: page.title,
116
+ theme: comment.theme,
117
+ lang: comment.lang
118
+ };
119
+ });
120
+ module.exports = Cusdis;
@@ -22,6 +22,8 @@ var _require = require('inferno'),
22
22
  Component = _require.Component;
23
23
  var _require2 = require('../../util/cache'),
24
24
  cacheComponent = _require2.cacheComponent;
25
+ var _require3 = require('../../util/script'),
26
+ toJs = _require3.toJs;
25
27
 
26
28
  /**
27
29
  * Disqus comment JSX component.
@@ -51,7 +53,7 @@ var Disqus = /*#__PURE__*/function (_Component) {
51
53
  if (!shortname) {
52
54
  return (0, _inferno.createVNode)(1, "div", "notification is-danger", [(0, _inferno.createTextVNode)("You forgot to set the "), (0, _inferno.createVNode)(1, "code", null, "shortname", 16), (0, _inferno.createTextVNode)(" for Disqus. Please set it in"), (0, _inferno.createTextVNode)(' '), (0, _inferno.createVNode)(1, "code", null, "_config.yml", 16), (0, _inferno.createTextVNode)(".")], 0);
53
55
  }
54
- var js = "var disqus_config = function () {\n this.page.url = '".concat(permalink, "';\n this.page.identifier = '").concat(disqusId || path, "';\n };\n (function() {\n var d = document, s = d.createElement('script'); \n s.src = '//' + '").concat(shortname, "' + '.disqus.com/embed.js';\n s.setAttribute('data-timestamp', +new Date());\n (d.head || d.body).appendChild(s);\n })();");
56
+ var js = "var disqus_config = function () {\n this.page.url = ".concat(toJs(permalink), ";\n this.page.identifier = ").concat(toJs(disqusId || path), ";\n };\n (function() {\n var d = document, s = d.createElement('script'); \n s.src = ").concat(toJs("//".concat(shortname, ".disqus.com/embed.js")), ";\n s.setAttribute('data-timestamp', +new Date());\n (d.head || d.body).appendChild(s);\n })();");
55
57
  return (0, _inferno.createFragment)([(0, _inferno.createVNode)(1, "div", null, (0, _inferno.createVNode)(1, "noscript", null, [(0, _inferno.createTextVNode)("Please enable JavaScript to view the"), (0, _inferno.createTextVNode)(' '), (0, _inferno.createVNode)(1, "a", null, "comments powered by Disqus.", 16, {
56
58
  "href": "//disqus.com/?ref_noscript"
57
59
  })], 0), 2, {
@@ -23,6 +23,7 @@ var _require = require('inferno'),
23
23
  var _require2 = require('../../util/cache'),
24
24
  cacheComponent = _require2.cacheComponent;
25
25
  var loadScripts = require('../../util/script');
26
+ var toJs = loadScripts.toJs;
26
27
 
27
28
  /**
28
29
  * DisqusJS comment JSX component.
@@ -67,12 +68,12 @@ var DisqusJs = /*#__PURE__*/function (_Component) {
67
68
  siteTitle = _this$props.siteTitle,
68
69
  jsUrl = _this$props.jsUrl,
69
70
  cssUrl = _this$props.cssUrl;
70
- if (!shortname) {
71
+ if (!shortname || !apiKey) {
71
72
  return (0, _inferno.createVNode)(1, "div", "notification is-danger", [(0, _inferno.createTextVNode)("You forgot to set the "), (0, _inferno.createVNode)(1, "code", null, "shortname", 16), (0, _inferno.createTextVNode)(" or "), (0, _inferno.createVNode)(1, "code", null, "api_key", 16), (0, _inferno.createTextVNode)(" for Disqus. Please set it in "), (0, _inferno.createVNode)(1, "code", null, "_config.yml", 16), (0, _inferno.createTextVNode)(".")], 4);
72
73
  }
73
74
  var url = permalink || path;
74
75
  var identifier = disqusId || path;
75
- var js = "new DisqusJS({\n shortname: '".concat(shortname, "',\n apikey: ").concat(JSON.stringify(apiKey), ",\n ").concat(siteTitle ? "siteName: ".concat(JSON.stringify(siteTitle), ",") : '', "\n ").concat(identifier ? "identifier: ".concat(JSON.stringify(identifier), ",") : '', "\n ").concat(url ? "url: ".concat(JSON.stringify(url), ",") : '', "\n ").concat(pageTitle ? "title: ".concat(JSON.stringify(pageTitle), ",") : '', "\n ").concat(api ? "api: ".concat(JSON.stringify(api), ",") : '', "\n ").concat(admin ? "admin: ".concat(JSON.stringify(admin), ",") : '', "\n ").concat(adminLabel ? "adminLabel: ".concat(JSON.stringify(adminLabel), ",") : '', "\n ").concat(nesting ? "nesting: ".concat(JSON.stringify(nesting), ",") : '', "\n });");
76
+ var js = "new DisqusJS({\n shortname: ".concat(toJs(shortname), ",\n apikey: ").concat(toJs(apiKey), ",\n ").concat(siteTitle ? "siteName: ".concat(toJs(siteTitle), ",") : '', "\n ").concat(identifier ? "identifier: ".concat(toJs(identifier), ",") : '', "\n ").concat(url ? "url: ".concat(toJs(url), ",") : '', "\n ").concat(pageTitle ? "title: ".concat(toJs(pageTitle), ",") : '', "\n ").concat(api ? "api: ".concat(toJs(api), ",") : '', "\n ").concat(admin ? "admin: ".concat(toJs(admin), ",") : '', "\n ").concat(adminLabel ? "adminLabel: ".concat(toJs(adminLabel), ",") : '', "\n ").concat(nesting ? "nesting: ".concat(toJs(nesting), ",") : '', "\n });");
76
77
  return (0, _inferno.createFragment)([(0, _inferno.createVNode)(1, "link", null, null, 1, {
77
78
  "rel": "stylesheet",
78
79
  "href": cssUrl,
@@ -22,6 +22,8 @@ var _require = require('inferno'),
22
22
  Component = _require.Component;
23
23
  var _require2 = require('../../util/cache'),
24
24
  cacheComponent = _require2.cacheComponent;
25
+ var _require3 = require('../../util/script'),
26
+ toJs = _require3.toJs;
25
27
 
26
28
  /**
27
29
  * Facebook comment JSX component.
@@ -45,7 +47,7 @@ var Facebook = /*#__PURE__*/function (_Component) {
45
47
  language = _this$props.language,
46
48
  permalink = _this$props.permalink;
47
49
  var fbLanguage = language.split('-').join('_');
48
- var js = "(function(d, s, id) {\n var js, fjs = d.getElementsByTagName(s)[0];\n if (d.getElementById(id)) return;\n js = d.createElement(s); js.id = id;\n js.src = \"//connect.facebook.net/".concat(fbLanguage, "/sdk.js#xfbml=1&version=v12.0\";\n fjs.parentNode.insertBefore(js, fjs);\n }(document, 'script', 'facebook-jssdk'));");
50
+ var js = "(function(d, s, id) {\n var js, fjs = d.getElementsByTagName(s)[0];\n // After a PJAX page switch, the SDK is loaded, so render the new comments box with it\n if (d.getElementById(id)) {\n if (window.FB) FB.XFBML.parse();\n return;\n }\n js = d.createElement(s); js.id = id;\n js.src = ".concat(toJs("//connect.facebook.net/".concat(fbLanguage, "/sdk.js#xfbml=1&version=v12.0")), ";\n fjs.parentNode.insertBefore(js, fjs);\n }(document, 'script', 'facebook-jssdk'));");
49
51
  return (0, _inferno.createFragment)([(0, _inferno.createVNode)(1, "div", "fb-comments", null, 1, {
50
52
  "data-width": "100%",
51
53
  "data-href": permalink,