hexo-component-inferno 4.0.0 → 4.1.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.
@@ -0,0 +1,133 @@
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
+ var _require4 = require('../../util/appearance'),
28
+ isDark = _require4.isDark;
29
+
30
+ /**
31
+ * Beaudar comment JSX component.
32
+ * <p>
33
+ * Beaudar is a Chinese fork of Utterances that keeps comments in GitHub issues.
34
+ *
35
+ * @see https://github.com/beaudar/beaudar
36
+ * @example
37
+ * <Beaudar
38
+ * repo="******"
39
+ * branch="main"
40
+ * issueTerm="******"
41
+ * issueNumber={123}
42
+ * label="******"
43
+ * theme="******"
44
+ * darkTheme="******" />
45
+ */
46
+ var Beaudar = /*#__PURE__*/function (_Component) {
47
+ function Beaudar() {
48
+ _classCallCheck(this, Beaudar);
49
+ return _callSuper(this, Beaudar, arguments);
50
+ }
51
+ _inherits(Beaudar, _Component);
52
+ return _createClass(Beaudar, [{
53
+ key: "render",
54
+ value: function render() {
55
+ var _this$props = this.props,
56
+ repo = _this$props.repo,
57
+ branch = _this$props.branch,
58
+ issueTerm = _this$props.issueTerm,
59
+ issueNumber = _this$props.issueNumber,
60
+ label = _this$props.label,
61
+ theme = _this$props.theme,
62
+ darkTheme = _this$props.darkTheme;
63
+ if (!repo || !issueTerm && !issueNumber) {
64
+ 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);
65
+ }
66
+ var config = {
67
+ repo: repo
68
+ };
69
+ if (branch) {
70
+ config.branch = branch;
71
+ }
72
+ if (issueTerm) {
73
+ config['issue-term'] = issueTerm;
74
+ } else {
75
+ config['issue-number'] = issueNumber;
76
+ }
77
+ if (label) {
78
+ config.label = label;
79
+ }
80
+ config.crossorigin = 'anonymous';
81
+ // Use the dark theme when the page looks dark
82
+ var js = appendScript('#beaudar-thread', 'https://beaudar.lipk.org/client.js', config, {
83
+ theme: "".concat(isDark(), " ? ").concat(JSON.stringify(darkTheme || 'github-dark'), " : ").concat(JSON.stringify(theme || 'github-light'))
84
+ });
85
+ return (0, _inferno.createFragment)([(0, _inferno.createVNode)(1, "div", null, null, 1, {
86
+ "id": "beaudar-thread"
87
+ }), (0, _inferno.createVNode)(1, "script", null, null, 1, {
88
+ "dangerouslySetInnerHTML": {
89
+ __html: js
90
+ }
91
+ })], 4);
92
+ }
93
+ }]);
94
+ }(Component);
95
+ /**
96
+ * Cacheable Beaudar comment JSX component.
97
+ * <p>
98
+ * This class is supposed to be used in combination with the <code>locals</code> hexo filter
99
+ * ({@link module:hexo/filter/locals}).
100
+ *
101
+ * @see module:util/cache.cacheComponent
102
+ * @example
103
+ * <Beaudar.Cacheable
104
+ * comment={{
105
+ * repo: "******",
106
+ * branch: "main",
107
+ * issue_term: "******",
108
+ * issue_number: {123},
109
+ * label: "******",
110
+ * theme: "******",
111
+ * dark_theme: "******"
112
+ * }} />
113
+ */
114
+ Beaudar.Cacheable = cacheComponent(Beaudar, 'comment.beaudar', function (props) {
115
+ var _props$comment = props.comment,
116
+ repo = _props$comment.repo,
117
+ branch = _props$comment.branch,
118
+ issue_term = _props$comment.issue_term,
119
+ issue_number = _props$comment.issue_number,
120
+ label = _props$comment.label,
121
+ theme = _props$comment.theme,
122
+ dark_theme = _props$comment.dark_theme;
123
+ return {
124
+ repo: repo,
125
+ branch: branch,
126
+ issueTerm: issue_term,
127
+ issueNumber: issue_number,
128
+ label: label,
129
+ theme: theme,
130
+ darkTheme: dark_theme
131
+ };
132
+ });
133
+ module.exports = Beaudar;
@@ -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
+ * 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 _require3 = require('../../util/appearance'),
27
+ getAppearance = _require3.getAppearance;
28
+
29
+ /**
30
+ * Cusdis comment JSX component.
31
+ *
32
+ * @see https://cusdis.com/doc
33
+ * @example
34
+ * <Cusdis
35
+ * host="https://cusdis.com"
36
+ * appId="******"
37
+ * pageId="/path/to/page/"
38
+ * pageUrl="https://example.com/path/to/page/"
39
+ * pageTitle="******"
40
+ * theme="auto"
41
+ * lang="zh-cn" />
42
+ */
43
+ var Cusdis = /*#__PURE__*/function (_Component) {
44
+ function Cusdis() {
45
+ _classCallCheck(this, Cusdis);
46
+ return _callSuper(this, Cusdis, arguments);
47
+ }
48
+ _inherits(Cusdis, _Component);
49
+ return _createClass(Cusdis, [{
50
+ key: "render",
51
+ value: function render() {
52
+ var _this$props = this.props,
53
+ _this$props$host = _this$props.host,
54
+ host = _this$props$host === void 0 ? 'https://cusdis.com' : _this$props$host,
55
+ appId = _this$props.appId,
56
+ pageId = _this$props.pageId,
57
+ pageUrl = _this$props.pageUrl,
58
+ pageTitle = _this$props.pageTitle,
59
+ theme = _this$props.theme,
60
+ lang = _this$props.lang;
61
+ if (!appId) {
62
+ 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);
63
+ }
64
+ var urls = ["".concat(host, "/js/cusdis.es.js")];
65
+ if (lang) {
66
+ urls.unshift("".concat(host, "/js/widget/lang/").concat(lang, ".js"));
67
+ }
68
+ // Without the theme option, follow the appearance of the page (light, dark, or auto, the same values
69
+ // as the themes of Cusdis). The Cusdis script renders #cusdis_thread when it loads, so render it
70
+ // directly only when the script is already loaded, e.g., when PJAX runs this code again.
71
+ var js = "(function () {\n var element = document.getElementById('cusdis_thread');\n if (!element) {\n return;\n }\n element.setAttribute('data-theme', ".concat(theme ? JSON.stringify(theme) : getAppearance(), ");\n if (window.renderCusdis) {\n window.renderCusdis(element);\n return;\n }\n ").concat(loadScripts(urls, ''), "\n })();");
72
+ return (0, _inferno.createFragment)([(0, _inferno.createVNode)(1, "div", null, null, 1, {
73
+ "id": "cusdis_thread",
74
+ "data-host": host,
75
+ "data-app-id": appId,
76
+ "data-page-id": pageId,
77
+ "data-page-url": pageUrl,
78
+ "data-page-title": pageTitle
79
+ }), (0, _inferno.createVNode)(1, "script", null, null, 1, {
80
+ "dangerouslySetInnerHTML": {
81
+ __html: js
82
+ }
83
+ })], 4);
84
+ }
85
+ }]);
86
+ }(Component);
87
+ /**
88
+ * Cacheable Cusdis comment JSX component.
89
+ * <p>
90
+ * This class is supposed to be used in combination with the <code>locals</code> hexo filter
91
+ * ({@link module:hexo/filter/locals}).
92
+ *
93
+ * @see module:util/cache.cacheComponent
94
+ * @example
95
+ * <Cusdis.Cacheable
96
+ * comment={{
97
+ * host: "https://cusdis.com",
98
+ * app_id: "******",
99
+ * theme: "auto",
100
+ * lang: "zh-cn"
101
+ * }}
102
+ * page={{ path: "/path/to/page/", permalink: "******", title: "******" }}
103
+ * helper={{ url_for: function() {...} }} />
104
+ */
105
+ Cusdis.Cacheable = cacheComponent(Cusdis, 'comment.cusdis', function (props) {
106
+ var comment = props.comment,
107
+ helper = props.helper,
108
+ page = props.page;
109
+ return {
110
+ host: comment.host ? comment.host.replace(/\/+$/, '') : undefined,
111
+ appId: comment.app_id,
112
+ pageId: helper.url_for(page.path),
113
+ pageUrl: page.permalink,
114
+ pageTitle: page.title,
115
+ theme: comment.theme,
116
+ lang: comment.lang
117
+ };
118
+ });
119
+ module.exports = Cusdis;
@@ -2,9 +2,6 @@
2
2
 
3
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
4
  var _inferno = require("inferno");
5
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
8
5
  function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
9
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); } }
10
7
  function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
@@ -25,6 +22,10 @@ var _require = require('inferno'),
25
22
  Component = _require.Component;
26
23
  var _require2 = require('../../util/cache'),
27
24
  cacheComponent = _require2.cacheComponent;
25
+ var _require3 = require('../../util/script'),
26
+ appendScript = _require3.appendScript;
27
+ var _require4 = require('../../util/appearance'),
28
+ isDark = _require4.isDark;
28
29
 
29
30
  /**
30
31
  * Giscus comment JSX component.
@@ -42,6 +43,7 @@ var _require2 = require('../../util/cache'),
42
43
  * emitMetadata={0}
43
44
  * inputPosition="******"
44
45
  * theme="******"
46
+ * darkTheme="******"
45
47
  * lang="******"
46
48
  * lazy="******" />
47
49
  */
@@ -66,6 +68,7 @@ var Giscus = /*#__PURE__*/function (_Component) {
66
68
  emitMetadata = _this$props.emitMetadata,
67
69
  inputPosition = _this$props.inputPosition,
68
70
  theme = _this$props.theme,
71
+ darkTheme = _this$props.darkTheme,
69
72
  customThemeCss = _this$props.customThemeCss,
70
73
  lang = _this$props.lang,
71
74
  lazy = _this$props.lazy;
@@ -75,9 +78,7 @@ var Giscus = /*#__PURE__*/function (_Component) {
75
78
  if ((mapping === 'specific' || mapping === 'number') && !term) {
76
79
  return (0, _inferno.createVNode)(1, "div", "notification is-danger", [(0, _inferno.createTextVNode)("You set "), (0, _inferno.createVNode)(1, "code", null, "mapping", 16), (0, _inferno.createTextVNode)(" to "), (0, _inferno.createVNode)(1, "code", null, "specific", 16), (0, _inferno.createTextVNode)(" or "), (0, _inferno.createVNode)(1, "code", null, "number", 16), (0, _inferno.createTextVNode)(", but did not set "), (0, _inferno.createVNode)(1, "code", null, "term", 16), (0, _inferno.createTextVNode)(" for Giscus. Please set "), (0, _inferno.createVNode)(1, "code", null, "term", 16), (0, _inferno.createTextVNode)(" in "), (0, _inferno.createVNode)(1, "code", null, "_config.yml", 16), (0, _inferno.createTextVNode)(".")], 4);
77
80
  }
78
- var config = {
79
- repo: repo
80
- };
81
+ var config = {};
81
82
  config['data-repo'] = repo;
82
83
  config['data-repo-id'] = repoId;
83
84
  config['data-category-id'] = categoryId;
@@ -91,6 +92,9 @@ var Giscus = /*#__PURE__*/function (_Component) {
91
92
  } else {
92
93
  config['data-mapping'] = 'pathname';
93
94
  }
95
+ if (term) {
96
+ config['data-term'] = term;
97
+ }
94
98
  if (strict) {
95
99
  config['data-strict'] = 1;
96
100
  } else {
@@ -111,18 +115,16 @@ var Giscus = /*#__PURE__*/function (_Component) {
111
115
  } else {
112
116
  config['data-input-position'] = 'top';
113
117
  }
114
- if (theme) {
115
- if (theme === 'custom') {
116
- if (customThemeCss) {
117
- config['data-theme'] = customThemeCss;
118
- } else {
119
- return (0, _inferno.createVNode)(1, "div", "notification is-danger", [(0, _inferno.createTextVNode)("You set "), (0, _inferno.createVNode)(1, "code", null, "theme", 16), (0, _inferno.createTextVNode)(" to "), (0, _inferno.createVNode)(1, "code", null, "custom", 16), (0, _inferno.createTextVNode)(", but did not apply a"), (0, _inferno.createTextVNode)(' '), (0, _inferno.createVNode)(1, "code", null, "customThemeCss", 16), (0, _inferno.createTextVNode)(" for Giscus. Please set it in "), (0, _inferno.createVNode)(1, "code", null, "_config.yml", 16), (0, _inferno.createTextVNode)(".")], 0);
120
- }
118
+ // Use the dark theme when the page looks dark, unless the theme is custom
119
+ var dynamicConfig = {};
120
+ if (theme === 'custom') {
121
+ if (customThemeCss) {
122
+ config['data-theme'] = customThemeCss;
121
123
  } else {
122
- config['data-theme'] = theme;
124
+ return (0, _inferno.createVNode)(1, "div", "notification is-danger", [(0, _inferno.createTextVNode)("You set "), (0, _inferno.createVNode)(1, "code", null, "theme", 16), (0, _inferno.createTextVNode)(" to "), (0, _inferno.createVNode)(1, "code", null, "custom", 16), (0, _inferno.createTextVNode)(", but did not apply a"), (0, _inferno.createTextVNode)(' '), (0, _inferno.createVNode)(1, "code", null, "customThemeCss", 16), (0, _inferno.createTextVNode)(" for Giscus. Please set it in "), (0, _inferno.createVNode)(1, "code", null, "_config.yml", 16), (0, _inferno.createTextVNode)(".")], 0);
123
125
  }
124
126
  } else {
125
- config['data-theme'] = 'noborder_light';
127
+ dynamicConfig['data-theme'] = "".concat(isDark(), " ? ").concat(JSON.stringify(darkTheme || 'noborder_dark'), " : ").concat(JSON.stringify(theme || 'noborder_light'));
126
128
  }
127
129
  if (lang) {
128
130
  config['data-lang'] = lang;
@@ -132,12 +134,17 @@ var Giscus = /*#__PURE__*/function (_Component) {
132
134
  if (lazy) {
133
135
  config['data-loading'] = 'lazy';
134
136
  }
135
- return (0, _inferno.normalizeProps)((0, _inferno.createVNode)(1, "script", null, null, 1, _objectSpread(_objectSpread({
136
- "src": "https://giscus.app/client.js"
137
- }, config), {}, {
138
- "crossorigin": "anonymous",
139
- "async": true
140
- })));
137
+ config.crossorigin = 'anonymous';
138
+ // Giscus puts its iframe into the element with the giscus class, so add its script to <head> to
139
+ // keep the number of scripts in the comment section the same for PJAX
140
+ var js = appendScript('head', 'https://giscus.app/client.js', config, dynamicConfig);
141
+ return (0, _inferno.createFragment)([(0, _inferno.createVNode)(1, "div", "giscus", null, 1, {
142
+ "id": "giscus-thread"
143
+ }), (0, _inferno.createVNode)(1, "script", null, null, 1, {
144
+ "dangerouslySetInnerHTML": {
145
+ __html: js
146
+ }
147
+ })], 4);
141
148
  }
142
149
  }]);
143
150
  }(Component);
@@ -161,6 +168,7 @@ var Giscus = /*#__PURE__*/function (_Component) {
161
168
  * emitMetadata: {false}
162
169
  * inputPosition: "******"
163
170
  * theme: "******"
171
+ * darkTheme: "******"
164
172
  * lang: "******"
165
173
  * lazy: "******"
166
174
  * }} />
@@ -178,6 +186,7 @@ Giscus.Cacheable = cacheComponent(Giscus, 'comment.giscus', function (props) {
178
186
  emitMetadata = _props$comment.emitMetadata,
179
187
  inputPosition = _props$comment.inputPosition,
180
188
  theme = _props$comment.theme,
189
+ darkTheme = _props$comment.darkTheme,
181
190
  customThemeCss = _props$comment.customThemeCss,
182
191
  lang = _props$comment.lang,
183
192
  lazy = _props$comment.lazy;
@@ -193,6 +202,7 @@ Giscus.Cacheable = cacheComponent(Giscus, 'comment.giscus', function (props) {
193
202
  emitMetadata: emitMetadata,
194
203
  inputPosition: inputPosition,
195
204
  theme: theme,
205
+ darkTheme: darkTheme,
196
206
  customThemeCss: customThemeCss,
197
207
  lang: lang,
198
208
  lazy: lazy
@@ -2,9 +2,6 @@
2
2
 
3
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
4
  var _inferno = require("inferno");
5
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
8
5
  function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
9
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); } }
10
7
  function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
@@ -25,6 +22,10 @@ var _require = require('inferno'),
25
22
  Component = _require.Component;
26
23
  var _require2 = require('../../util/cache'),
27
24
  cacheComponent = _require2.cacheComponent;
25
+ var _require3 = require('../../util/script'),
26
+ appendScript = _require3.appendScript;
27
+ var _require4 = require('../../util/appearance'),
28
+ isDark = _require4.isDark;
28
29
 
29
30
  /**
30
31
  * Utterances comment JSX component.
@@ -36,7 +37,8 @@ var _require2 = require('../../util/cache'),
36
37
  * issueTerm="******"
37
38
  * issueNumber={123}
38
39
  * label="******"
39
- * theme="******" />
40
+ * theme="******"
41
+ * darkTheme="******" />
40
42
  */
41
43
  var Utterances = /*#__PURE__*/function (_Component) {
42
44
  function Utterances() {
@@ -52,7 +54,8 @@ var Utterances = /*#__PURE__*/function (_Component) {
52
54
  issueTerm = _this$props.issueTerm,
53
55
  issueNumber = _this$props.issueNumber,
54
56
  label = _this$props.label,
55
- theme = _this$props.theme;
57
+ theme = _this$props.theme,
58
+ darkTheme = _this$props.darkTheme;
56
59
  if (!repo || !issueTerm && !issueNumber) {
57
60
  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 Utterances. Please set it in "), (0, _inferno.createVNode)(1, "code", null, "_config.yml", 16), (0, _inferno.createTextVNode)(".")], 0);
58
61
  }
@@ -67,15 +70,18 @@ var Utterances = /*#__PURE__*/function (_Component) {
67
70
  if (label) {
68
71
  config.label = label;
69
72
  }
70
- if (theme) {
71
- config.theme = theme;
72
- }
73
- return (0, _inferno.normalizeProps)((0, _inferno.createVNode)(1, "script", null, null, 1, _objectSpread(_objectSpread({
74
- "src": "https://utteranc.es/client.js"
75
- }, config), {}, {
76
- "crossorigin": "anonymous",
77
- "async": true
78
- })));
73
+ config.crossorigin = 'anonymous';
74
+ // Use the dark theme when the page looks dark
75
+ var js = appendScript('#utterances-thread', 'https://utteranc.es/client.js', config, {
76
+ theme: "".concat(isDark(), " ? ").concat(JSON.stringify(darkTheme || 'github-dark'), " : ").concat(JSON.stringify(theme || 'github-light'))
77
+ });
78
+ return (0, _inferno.createFragment)([(0, _inferno.createVNode)(1, "div", null, null, 1, {
79
+ "id": "utterances-thread"
80
+ }), (0, _inferno.createVNode)(1, "script", null, null, 1, {
81
+ "dangerouslySetInnerHTML": {
82
+ __html: js
83
+ }
84
+ })], 4);
79
85
  }
80
86
  }]);
81
87
  }(Component);
@@ -94,6 +100,7 @@ var Utterances = /*#__PURE__*/function (_Component) {
94
100
  * issue_number: {123}
95
101
  * label: "******"
96
102
  * theme: "******"
103
+ * dark_theme: "******"
97
104
  * }} />
98
105
  */
99
106
  Utterances.Cacheable = cacheComponent(Utterances, 'comment.utterances', function (props) {
@@ -102,13 +109,15 @@ Utterances.Cacheable = cacheComponent(Utterances, 'comment.utterances', function
102
109
  issue_term = _props$comment.issue_term,
103
110
  issue_number = _props$comment.issue_number,
104
111
  label = _props$comment.label,
105
- theme = _props$comment.theme;
112
+ theme = _props$comment.theme,
113
+ dark_theme = _props$comment.dark_theme;
106
114
  return {
107
115
  repo: repo,
108
116
  issueTerm: issue_term,
109
117
  issueNumber: issue_number,
110
118
  label: label,
111
- theme: theme
119
+ theme: theme,
120
+ darkTheme: dark_theme
112
121
  };
113
122
  });
114
123
  module.exports = Utterances;
@@ -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/appearance'),
26
+ getAppearance = _require3.getAppearance;
25
27
 
26
28
  /**
27
29
  * Waline comment JSX component.
@@ -68,8 +70,7 @@ var Waline = /*#__PURE__*/function (_Component) {
68
70
  locale = _this$props.locale,
69
71
  _this$props$emoji = _this$props.emoji,
70
72
  emoji = _this$props$emoji === void 0 ? ['https://cdn.jsdelivr.net/gh/walinejs/emojis/weibo'] : _this$props$emoji,
71
- _this$props$dark = _this$props.dark,
72
- dark = _this$props$dark === void 0 ? '' : _this$props$dark,
73
+ dark = _this$props.dark,
73
74
  _this$props$meta = _this$props.meta,
74
75
  meta = _this$props$meta === void 0 ? ['nick', 'mail', 'link'] : _this$props$meta,
75
76
  _this$props$requiredM = _this$props.requiredMeta,
@@ -99,7 +100,13 @@ var Waline = /*#__PURE__*/function (_Component) {
99
100
  if (!serverURL) {
100
101
  return (0, _inferno.createVNode)(1, "div", "notification is-danger", [(0, _inferno.createTextVNode)("You forgot to set the "), (0, _inferno.createVNode)(1, "code", null, "server_url", 16), (0, _inferno.createTextVNode)(" for Waline. Please set it in"), (0, _inferno.createTextVNode)(' '), (0, _inferno.createVNode)(1, "code", null, "_config.yml", 16), (0, _inferno.createTextVNode)(".")], 0);
101
102
  }
102
- var js = "import { init } from \"".concat(jsUrl, "\";\n init({\n el: '#waline-thread',\n serverURL: ").concat(JSON.stringify(serverURL), ",\n path: ").concat(path, ",\n ").concat(lang ? "lang: ".concat(JSON.stringify(lang), ",") : '', "\n ").concat(locale ? "locale: ".concat(JSON.stringify(locale), ",") : '', "\n ").concat(emoji ? "emoji: ".concat(JSON.stringify(emoji), ",") : '', "\n ").concat(dark ? "dark: ".concat(JSON.stringify(dark), ",") : '', "\n ").concat(meta ? "meta: ".concat(JSON.stringify(meta), ",") : '', "\n ").concat(Array.isArray(requiredMeta) ? "requiredMeta: ".concat(JSON.stringify(requiredMeta), ",") : '', "\n ").concat(login ? "login: ".concat(JSON.stringify(login), ",") : '', "\n ").concat(wordLimit ? "wordLimit: ".concat(JSON.stringify(wordLimit), ",") : '', "\n ").concat(pageSize ? "pageSize: ".concat(JSON.stringify(pageSize), ",") : '', "\n ").concat(imageUploader === false ? "imageUploader: false," : '', "\n ").concat(highlighter === false ? "highlighter: false," : '', "\n ").concat(texRenderer === false ? "texRenderer: false," : '', "\n ").concat(search === false ? "search: false," : '', "\n ").concat(typeof pageview !== 'undefined' ? "pageview: ".concat(JSON.stringify(pageview), ",") : '', "\n ").concat(typeof comment !== 'undefined' ? "comment: ".concat(JSON.stringify(comment), ",") : '', "\n ", "copyright: ".concat(JSON.stringify(copyright), ","), "\n });");
103
+ // Without the dark option, follow the appearance of the page: the system color scheme for the auto
104
+ // appearance, or the data-appearance="dark" attribute of <html> otherwise
105
+ var darkOption = dark === null || typeof dark === 'undefined' || dark === '' ? "".concat(getAppearance(), " === 'auto' ? 'auto' : 'html[data-appearance=\"dark\"]'") : JSON.stringify(dark);
106
+ // Use a classic script with a dynamic import instead of a module script, so that PJAX, which only
107
+ // runs classic scripts, initializes Waline again after switching pages. The previous instance,
108
+ // whose element PJAX has replaced, is destroyed first.
109
+ var js = "import(".concat(JSON.stringify(jsUrl), ").then(function (Waline) {\n if (window.__walineInstance) {\n window.__walineInstance.destroy();\n }\n window.__walineInstance = Waline.init({\n el: '#waline-thread',\n serverURL: ").concat(JSON.stringify(serverURL), ",\n path: ").concat(path, ",\n ").concat(lang ? "lang: ".concat(JSON.stringify(lang), ",") : '', "\n ").concat(locale ? "locale: ".concat(JSON.stringify(locale), ",") : '', "\n ").concat(emoji ? "emoji: ".concat(JSON.stringify(emoji), ",") : '', "\n dark: ").concat(darkOption, ",\n ").concat(meta ? "meta: ".concat(JSON.stringify(meta), ",") : '', "\n ").concat(Array.isArray(requiredMeta) ? "requiredMeta: ".concat(JSON.stringify(requiredMeta), ",") : '', "\n ").concat(login ? "login: ".concat(JSON.stringify(login), ",") : '', "\n ").concat(wordLimit ? "wordLimit: ".concat(JSON.stringify(wordLimit), ",") : '', "\n ").concat(pageSize ? "pageSize: ".concat(JSON.stringify(pageSize), ",") : '', "\n ").concat(imageUploader === false ? "imageUploader: false," : '', "\n ").concat(highlighter === false ? "highlighter: false," : '', "\n ").concat(texRenderer === false ? "texRenderer: false," : '', "\n ").concat(search === false ? "search: false," : '', "\n ").concat(typeof pageview !== 'undefined' ? "pageview: ".concat(JSON.stringify(pageview), ",") : '', "\n ").concat(typeof comment !== 'undefined' ? "comment: ".concat(JSON.stringify(comment), ",") : '', "\n ", "copyright: ".concat(JSON.stringify(copyright), ","), "\n });\n });");
103
110
  return (0, _inferno.createFragment)([(0, _inferno.createVNode)(1, "div", "content", null, 1, {
104
111
  "id": "waline-thread"
105
112
  }), (0, _inferno.createVNode)(1, "link", null, null, 1, {
@@ -108,7 +115,6 @@ var Waline = /*#__PURE__*/function (_Component) {
108
115
  "media": "print",
109
116
  "onload": "this.media='all'"
110
117
  }), (0, _inferno.createVNode)(1, "script", null, null, 1, {
111
- "type": "module",
112
118
  "dangerouslySetInnerHTML": {
113
119
  __html: js
114
120
  }
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+
3
+ var _inferno = require("inferno");
4
+ 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); }
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
+ * Waline page view counter plugin JSX component.
19
+ * @module view/plugin/waline_pageview
20
+ */
21
+ var _require = require('inferno'),
22
+ Component = _require.Component;
23
+ var _require2 = require('../../util/cache'),
24
+ cacheComponent = _require2.cacheComponent;
25
+
26
+ /**
27
+ * Waline page view counter plugin JSX component.
28
+ * <p>
29
+ * It counts a view of the current page, and shows the page views in the elements with the
30
+ * <code>waline-pageview-count</code> class, of the page in their <code>data-path</code> attribute, or of
31
+ * the current page without it. It counts and shows them again after switching pages with PJAX.
32
+ *
33
+ * @see https://waline.js.org/en/guide/features/pageview.html
34
+ * @example
35
+ * <WalinePageview
36
+ * serverURL="https://path/to/waline/server"
37
+ * jsUrl="/path/to/pageview.js" />
38
+ */
39
+ var WalinePageview = /*#__PURE__*/function (_Component) {
40
+ function WalinePageview() {
41
+ _classCallCheck(this, WalinePageview);
42
+ return _callSuper(this, WalinePageview, arguments);
43
+ }
44
+ _inherits(WalinePageview, _Component);
45
+ return _createClass(WalinePageview, [{
46
+ key: "render",
47
+ value: function render() {
48
+ var _this$props = this.props,
49
+ serverURL = _this$props.serverURL,
50
+ jsUrl = _this$props.jsUrl;
51
+
52
+ // Waline publishes the counter as an ES module, so load it with a dynamic import
53
+ var js = "(function () {\n var abort = null;\n function count() {\n import(".concat(JSON.stringify(jsUrl), ").then(function (Waline) {\n if (abort) {\n abort();\n }\n abort = Waline.pageviewCount({\n serverURL: ").concat(JSON.stringify(serverURL), ",\n path: window.location.pathname,\n });\n });\n }\n count();\n document.addEventListener('pjax:complete', count);\n })();");
54
+ return (0, _inferno.createVNode)(1, "script", null, null, 1, {
55
+ "dangerouslySetInnerHTML": {
56
+ __html: js
57
+ }
58
+ });
59
+ }
60
+ }]);
61
+ }(Component);
62
+ /**
63
+ * Cacheable Waline page view counter plugin JSX component.
64
+ * <p>
65
+ * This class is supposed to be used in combination with the <code>locals</code> hexo filter
66
+ * ({@link module:hexo/filter/locals}).
67
+ *
68
+ * @see module:util/cache.cacheComponent
69
+ * @example
70
+ * <WalinePageview.Cacheable
71
+ * head={false}
72
+ * plugin={{ server_url: 'https://path/to/waline/server' }}
73
+ * config={{ comment: { type: 'waline', server_url: 'https://path/to/waline/server' } }}
74
+ * helper={{ cdn: function() {...} }} />
75
+ */
76
+ WalinePageview.Cacheable = cacheComponent(WalinePageview, 'plugin.walinepageview', function (props) {
77
+ var head = props.head,
78
+ plugin = props.plugin,
79
+ config = props.config,
80
+ helper = props.helper;
81
+ if (head || !plugin) {
82
+ return null;
83
+ }
84
+ // Use the server of the Waline comments without the server_url option
85
+ var comment = config.comment;
86
+ var serverURL = _typeof(plugin) === 'object' ? plugin.server_url : null;
87
+ if (!serverURL && comment && comment.type === 'waline') {
88
+ serverURL = comment.server_url;
89
+ }
90
+ if (!serverURL) {
91
+ return null;
92
+ }
93
+ return {
94
+ serverURL: serverURL,
95
+ jsUrl: helper.cdn('@waline/client', '3.3.0', 'dist/pageview.js')
96
+ };
97
+ });
98
+ module.exports = WalinePageview;