hexo-component-inferno 4.2.2 → 5.0.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 (69) hide show
  1. package/README.md +5 -18
  2. package/asset/css/github-calendar.css +41 -0
  3. package/asset/js/algolia.js +18 -69
  4. package/asset/js/github-calendar.js +185 -0
  5. package/asset/js/google_cse.js +19 -68
  6. package/asset/js/insight.js +45 -208
  7. package/lib/core/commented_yaml.js +35 -0
  8. package/lib/core/default_value.js +150 -0
  9. package/lib/core/schema.js +8 -196
  10. package/lib/core/schema_util.js +14 -0
  11. package/lib/hexo/helper/cdn.js +10 -97
  12. package/lib/hexo/tag/tabs.js +4 -84
  13. package/lib/schema/comment/artalk.json +7 -1
  14. package/lib/schema/comment/facebook.json +1 -1
  15. package/lib/schema/comment/gitalk.json +23 -6
  16. package/lib/schema/comment/gitment.json +1 -1
  17. package/lib/schema/comment/twikoo.json +3 -3
  18. package/lib/schema/comment/waline.json +28 -3
  19. package/lib/schema/misc/open_graph.json +2 -1
  20. package/lib/schema/plugin/cookie_consent.json +2 -2
  21. package/lib/schema/plugin/mathjax.json +1 -1
  22. package/lib/schema/plugin/outdated_browser.json +1 -1
  23. package/lib/schema/share/bdshare.json +1 -1
  24. package/lib/schema/share/sharejs.json +1 -1
  25. package/lib/schema/share/web_share.json +13 -0
  26. package/lib/schema/widget/github_calendar.json +30 -0
  27. package/lib/schema/widget/profile.json +67 -0
  28. package/lib/util/archives.js +86 -0
  29. package/lib/util/categories.js +102 -0
  30. package/lib/util/cdn-rules.js +109 -0
  31. package/lib/util/cdn.js +116 -0
  32. package/lib/util/consent.js +122 -0
  33. package/lib/util/deprecate.js +1 -1
  34. package/lib/util/gallery.js +227 -0
  35. package/lib/util/insight-search.js +98 -0
  36. package/lib/util/searchbox.js +88 -0
  37. package/lib/util/tab-options.js +109 -0
  38. package/lib/view/comment/artalk.js +24 -6
  39. package/lib/view/comment/disqus.js +1 -1
  40. package/lib/view/comment/disqusjs.js +7 -6
  41. package/lib/view/comment/facebook.js +3 -16
  42. package/lib/view/comment/gitalk.js +18 -15
  43. package/lib/view/comment/gitment.js +2 -2
  44. package/lib/view/comment/twikoo.js +5 -3
  45. package/lib/view/comment/valine.js +4 -3
  46. package/lib/view/comment/waline.js +8 -6
  47. package/lib/view/misc/open_graph.js +3 -5
  48. package/lib/view/plugin/cookie_consent.js +8 -7
  49. package/lib/view/plugin/gallery.js +42 -19
  50. package/lib/view/plugin/katex.js +4 -4
  51. package/lib/view/plugin/mathjax.js +10 -7
  52. package/lib/view/plugin/outdated_browser.js +59 -45
  53. package/lib/view/plugin/progressbar.js +6 -1
  54. package/lib/view/plugin/waline_pageview.js +2 -2
  55. package/lib/view/search/algolia.js +8 -3
  56. package/lib/view/search/google_cse.js +13 -10
  57. package/lib/view/search/insight.js +9 -2
  58. package/lib/view/share/addthis.js +4 -9
  59. package/lib/view/share/addtoany.js +23 -5
  60. package/lib/view/share/bdshare.js +9 -30
  61. package/lib/view/share/sharejs.js +7 -34
  62. package/lib/view/share/sharethis.js +21 -6
  63. package/lib/view/share/web_share.js +153 -0
  64. package/lib/view/widget/archives.js +19 -71
  65. package/lib/view/widget/categories.js +20 -67
  66. package/lib/view/widget/github_calendar.js +94 -0
  67. package/lib/view/widget/profile.js +194 -0
  68. package/lib/view/widget/subscribe_email.js +4 -26
  69. package/package.json +6 -4
@@ -0,0 +1,153 @@
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
+ * Native Web Share button JSX component.
19
+ * @module view/share/web_share
20
+ */
21
+ var _require = require('inferno'),
22
+ Component = _require.Component;
23
+ var _require2 = require('../../util/cache'),
24
+ cacheComponent = _require2.cacheComponent;
25
+
26
+ // Brand colors only: the consuming theme owns button geometry and interaction.
27
+ var NETWORKS = [{
28
+ id: 'x',
29
+ name: 'X',
30
+ background: '#000000',
31
+ foreground: '#ffffff'
32
+ }, {
33
+ id: 'facebook',
34
+ name: 'Facebook',
35
+ icon: 'fab fa-facebook-f',
36
+ background: '#0866ff',
37
+ foreground: '#ffffff'
38
+ }, {
39
+ id: 'weibo',
40
+ name: 'Weibo',
41
+ icon: 'fab fa-weibo',
42
+ background: '#e6162d',
43
+ foreground: '#ffffff'
44
+ }, {
45
+ id: 'telegram',
46
+ name: 'Telegram',
47
+ icon: 'fab fa-telegram-plane',
48
+ background: '#26a5e4',
49
+ foreground: '#ffffff'
50
+ }, {
51
+ id: 'linkedin',
52
+ name: 'LinkedIn',
53
+ icon: 'fab fa-linkedin-in',
54
+ background: '#0a66c2',
55
+ foreground: '#ffffff'
56
+ }];
57
+ function shareUrl(network, url, title) {
58
+ var link = encodeURIComponent(url);
59
+ var text = encodeURIComponent(title);
60
+ return {
61
+ x: 'https://twitter.com/intent/tweet?url=' + link + '&text=' + text,
62
+ facebook: 'https://www.facebook.com/sharer/sharer.php?u=' + link,
63
+ weibo: 'https://service.weibo.com/share/share.php?url=' + link + '&title=' + text,
64
+ telegram: 'https://t.me/share/url?url=' + link + '&text=' + text,
65
+ linkedin: 'https://www.linkedin.com/sharing/share-offsite/?url=' + link
66
+ }[network];
67
+ }
68
+
69
+ /**
70
+ * Native Web Share button JSX component.
71
+ *
72
+ * @example
73
+ * <WebShare />
74
+ */
75
+ var WebShare = /*#__PURE__*/function (_Component) {
76
+ function WebShare() {
77
+ _classCallCheck(this, WebShare);
78
+ return _callSuper(this, WebShare, arguments);
79
+ }
80
+ _inherits(WebShare, _Component);
81
+ return _createClass(WebShare, [{
82
+ key: "render",
83
+ value: function render() {
84
+ var _this$props = this.props,
85
+ _this$props$label = _this$props.label,
86
+ label = _this$props$label === void 0 ? 'More' : _this$props$label,
87
+ url = _this$props.url,
88
+ title = _this$props.title;
89
+ var js = "(function () {\n ".concat(shareUrl.toString(), "\n document.querySelectorAll('.hexo-component-share').forEach(function (container) {\n var button = container.querySelector('button');\n var status = container.querySelector('[role=\"status\"]');\n var native = container.querySelector('[data-share-native]');\n var data = { title: container.dataset.title || document.title, url: container.dataset.url || window.location.href };\n container.querySelectorAll('[data-share-network]').forEach(function (link) {\n link.href = shareUrl(link.dataset.shareNetwork, data.url, data.title);\n });\n button.hidden = false;\n native.hidden = false;\n button.disabled = typeof navigator.share !== 'function';\n status.hidden = !button.disabled;\n button.onclick = async function () {\n status.hidden = true;\n try {\n await navigator.share({ title: container.dataset.title || document.title, url: container.dataset.url || window.location.href });\n } catch (error) {\n if (error && error.name === 'AbortError') return;\n status.hidden = false;\n }\n };\n });\n })();");
90
+ return (0, _inferno.createFragment)([(0, _inferno.createVNode)(1, "div", "hexo-component-share", [(0, _inferno.createVNode)(1, "div", "buttons is-centered", [NETWORKS.map(function (network) {
91
+ return (0, _inferno.createVNode)(1, "a", "button", [(0, _inferno.createVNode)(1, "span", "icon", network.icon ? (0, _inferno.createVNode)(1, "i", network.icon) : (0, _inferno.createVNode)(32, "svg", null, (0, _inferno.createVNode)(32, "path", null, null, 1, {
92
+ "d": "M18.9 2H22l-6.8 7.8L23.2 22h-6.3L12 14.6 5.5 22H2.4l7.9-9L.8 2h6.5l4.5 6.7L18.9 2Zm-1.1 18h1.7L6.4 3.9H4.6L17.8 20Z"
93
+ }), 2, {
94
+ "width": "1em",
95
+ "height": "1em",
96
+ "viewBox": "0 0 24 24",
97
+ "fill": "currentColor"
98
+ }), 0, {
99
+ "aria-hidden": "true"
100
+ }), (0, _inferno.createVNode)(1, "span", null, network.name, 0)], 4, {
101
+ "style": "background-color:".concat(network.background, ";border-color:").concat(network.background, ";color:").concat(network.foreground),
102
+ "data-share-network": network.id,
103
+ "href": shareUrl(network.id, url || '', title || ''),
104
+ "target": "_blank",
105
+ "rel": "noopener noreferrer",
106
+ "aria-label": "Share on ".concat(network.name)
107
+ }, network.id);
108
+ }), (0, _inferno.createVNode)(1, "span", "has-text-centered", (0, _inferno.createVNode)(1, "button", "button", [(0, _inferno.createVNode)(1, "span", "icon", (0, _inferno.createVNode)(1, "i", "fas fa-share-alt"), 2, {
109
+ "aria-hidden": "true"
110
+ }), (0, _inferno.createVNode)(1, "span", null, label, 0)], 4, {
111
+ "type": "button",
112
+ "hidden": true
113
+ }), 2, {
114
+ "data-share-native": "",
115
+ "hidden": true
116
+ })], 0), (0, _inferno.createVNode)(1, "p", null, "System sharing is unavailable in this browser. You can use the platform buttons above.", 16, {
117
+ "role": "status",
118
+ "hidden": true
119
+ })], 4, {
120
+ "data-share-provider": "web_share",
121
+ "data-url": url,
122
+ "data-title": title
123
+ }), (0, _inferno.createVNode)(1, "script", null, null, 1, {
124
+ "dangerouslySetInnerHTML": {
125
+ __html: js
126
+ }
127
+ })], 4);
128
+ }
129
+ }]);
130
+ }(Component);
131
+ /**
132
+ * Cacheable Web Share button JSX component.
133
+ * <p>
134
+ * This class is supposed to be used in combination with the <code>locals</code> hexo filter
135
+ * ({@link module:hexo/filter/locals}).
136
+ *
137
+ * @see module:util/cache.cacheComponent
138
+ * @example
139
+ * <WebShare.Cacheable />
140
+ */
141
+ WebShare.Cacheable = cacheComponent(WebShare, 'share.web_share', function (_ref) {
142
+ var _ref$config = _ref.config,
143
+ config = _ref$config === void 0 ? {} : _ref$config,
144
+ _ref$page = _ref.page,
145
+ page = _ref$page === void 0 ? {} : _ref$page;
146
+ var language = page.lang || page.language || config.language || 'en';
147
+ return {
148
+ label: /^zh(?:-|$)/i.test([].concat(language)[0]) ? '更多' : 'More',
149
+ url: page.permalink,
150
+ title: page.title
151
+ };
152
+ });
153
+ module.exports = WebShare;
@@ -24,39 +24,9 @@ var _require2 = require('../../util/cache'),
24
24
  cacheComponent = _require2.cacheComponent;
25
25
  var _require3 = require('../../util/i18n'),
26
26
  translate = _require3.translate;
27
-
28
- /**
29
- * Get the first value that is set, i.e., neither null nor undefined.
30
- * @private
31
- */
32
- function firstSet() {
33
- for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
34
- values[_key] = arguments[_key];
35
- }
36
- return values.find(function (value) {
37
- return value !== null && typeof value !== 'undefined';
38
- });
39
- }
40
-
41
- /**
42
- * Convert a Hexo language code into a Moment.js locale name.
43
- * <p>
44
- * Same as Hexo's internal <code>toMomentLocale</code>, copied here so that the component does not
45
- * depend on Hexo's private modules.
46
- *
47
- * @param {string} lang Hexo language code, such as <code>zh-CN</code> or <code>en_US</code>.
48
- * @returns {string|undefined} Moment.js locale name.
49
- */
50
- function toMomentLocale(lang) {
51
- if (lang === undefined) {
52
- return undefined;
53
- }
54
- // moment.locale('') and moment.locale(null) both equal moment.locale('en')
55
- if (!lang || lang === 'en' || lang === 'default') {
56
- return 'en';
57
- }
58
- return lang.toLowerCase().replace('_', '-');
59
- }
27
+ var _require4 = require('../../util/archives'),
28
+ resolveArchiveOptions = _require4.resolveArchiveOptions,
29
+ groupArchives = _require4.groupArchives;
60
30
 
61
31
  /**
62
32
  * Archives widget JSX component.
@@ -137,13 +107,12 @@ Archives.Cacheable = cacheComponent(Archives, 'widget.archives', function (props
137
107
  page = props.page,
138
108
  helper = props.helper,
139
109
  widget = props.widget;
140
- // Options left empty in the config are null, which also take the defaults
141
- var groupBy = firstSet(widget.group_by, 'monthly');
142
- var order = firstSet(widget.order, -1);
143
- var format = widget.format,
144
- amount = widget.amount;
145
- // show_count, like the tags widget, or showCount, which this widget used to read
146
- var showCount = firstSet(widget.show_count, widget.showCount, true);
110
+ var _resolveArchiveOption = resolveArchiveOptions(widget),
111
+ groupBy = _resolveArchiveOption.groupBy,
112
+ order = _resolveArchiveOption.order,
113
+ format = _resolveArchiveOption.format,
114
+ amount = _resolveArchiveOption.amount,
115
+ showCount = _resolveArchiveOption.showCount;
147
116
  var url_for = helper.url_for,
148
117
  _p = helper._p,
149
118
  __ = helper.__;
@@ -151,33 +120,15 @@ Archives.Cacheable = cacheComponent(Archives, 'widget.archives', function (props
151
120
  if (!posts.length) {
152
121
  return null;
153
122
  }
154
- var language = toMomentLocale(page.lang || page.language || config.language);
155
- var data = [];
156
- var length = 0;
157
- posts.forEach(function (post) {
158
- // Clone the date object to avoid pollution
159
- var date = post.date.clone();
160
- if (config.timezone) {
161
- date = date.tz(config.timezone);
162
- }
163
- if (language) {
164
- date = date.locale(language);
165
- }
166
- var year = date.year();
167
- var month = date.month() + 1;
168
- var name = date.format(format || (groupBy === 'monthly' ? 'MMMM YYYY' : 'YYYY'));
169
- var lastData = data[length - 1];
170
- if (!lastData || lastData.name !== name) {
171
- length = data.push({
172
- name: name,
173
- year: year,
174
- month: month,
175
- count: 1
176
- });
177
- } else {
178
- lastData.count++;
179
- }
180
- });
123
+ var _groupArchives = groupArchives(posts, {
124
+ groupBy: groupBy,
125
+ format: format,
126
+ amount: amount,
127
+ language: page.lang || page.language || config.language,
128
+ timezone: config.timezone
129
+ }),
130
+ groups = _groupArchives.groups,
131
+ hasMore = _groupArchives.hasMore;
181
132
  var link = function link(item) {
182
133
  var url = "".concat(config.archive_dir, "/").concat(item.year, "/");
183
134
  if (groupBy === 'monthly') {
@@ -186,11 +137,8 @@ Archives.Cacheable = cacheComponent(Archives, 'widget.archives', function (props
186
137
  }
187
138
  return url_for(url);
188
139
  };
189
-
190
- // Link to the archive page when some of the archives are not shown
191
- var hasMore = amount > 0 && data.length > amount;
192
140
  return {
193
- items: (hasMore ? data.slice(0, amount) : data).map(function (item) {
141
+ items: groups.map(function (item) {
194
142
  return {
195
143
  name: item.name,
196
144
  count: item.count,
@@ -24,19 +24,10 @@ var _require2 = require('../../util/cache'),
24
24
  cacheComponent = _require2.cacheComponent;
25
25
  var _require3 = require('../../util/i18n'),
26
26
  translate = _require3.translate;
27
-
28
- /**
29
- * Get the first value that is set, i.e., neither null nor undefined.
30
- * @private
31
- */
32
- function firstSet() {
33
- for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
34
- values[_key] = arguments[_key];
35
- }
36
- return values.find(function (value) {
37
- return value !== null && typeof value !== 'undefined';
38
- });
39
- }
27
+ var _require4 = require('../../util/categories'),
28
+ resolveCategoryOptions = _require4.resolveCategoryOptions,
29
+ resolveCategoryDepth = _require4.resolveCategoryDepth,
30
+ prepareCategories = _require4.prepareCategories;
40
31
 
41
32
  /**
42
33
  * Categories widget JSX component.
@@ -128,68 +119,30 @@ Categories.Cacheable = cacheComponent(Categories, 'widget.categories', function
128
119
  var _widget$categories = widget.categories,
129
120
  categories = _widget$categories === void 0 ? props.site.categories : _widget$categories,
130
121
  amount = widget.amount;
131
- // Options left empty in the config are null, which also take the defaults
132
- var order = firstSet(widget.order, 1);
133
- // Snake case, like the tags widget, or camel case, which this widget used to read
134
- var orderBy = firstSet(widget.order_by, widget.orderBy, 'name');
135
- var showCurrent = firstSet(widget.show_current, widget.showCurrent, false);
136
- var showCount = firstSet(widget.show_count, widget.showCount, true);
122
+ var _resolveCategoryOptio = resolveCategoryOptions(widget),
123
+ order = _resolveCategoryOptio.order,
124
+ orderBy = _resolveCategoryOptio.orderBy,
125
+ showCurrent = _resolveCategoryOptio.showCurrent,
126
+ showCount = _resolveCategoryOptio.showCount;
137
127
  var url_for = helper.url_for,
138
128
  _p = helper._p,
139
129
  __ = helper.__;
140
130
  if (!categories || !categories.length) {
141
131
  return null;
142
132
  }
143
-
144
- // 0 or no depth shows all levels
145
- var depth = parseInt(firstSet(widget.depth, props.depth), 10) || 0;
146
- function prepareQuery(parent) {
147
- var query = {};
148
- if (parent) {
149
- query.parent = parent;
150
- } else {
151
- query.parent = {
152
- $exists: false
153
- };
154
- }
155
- return categories.find(query).sort(orderBy, order).filter(function (cat) {
156
- return cat.length;
157
- });
158
- }
159
- function hierarchicalList(level, parent) {
160
- return prepareQuery(parent).map(function (cat, i) {
161
- var children = [];
162
- if (!depth || level + 1 < depth) {
163
- children = hierarchicalList(level + 1, cat._id);
164
- }
165
- var isCurrent = false;
166
- if (showCurrent && page) {
167
- for (var j = 0; j < cat.length; j++) {
168
- var post = cat.posts.data[j];
169
- if (post && post._id === page._id) {
170
- isCurrent = true;
171
- break;
172
- }
173
- }
174
- // special case: category page
175
- isCurrent = isCurrent || page.base && page.base.startsWith(cat.path);
176
- }
177
- return {
178
- children: children,
179
- isCurrent: isCurrent,
180
- name: cat.name,
181
- count: cat.length,
182
- url: url_for(cat.path)
183
- };
184
- });
185
- }
186
-
187
- // Only limit the top-level categories, and link to the category page when some are not shown
188
- var list = hierarchicalList(0);
189
- var hasMore = amount > 0 && list.length > amount;
133
+ var depth = resolveCategoryDepth(widget.depth, props.depth);
134
+ var _prepareCategories = prepareCategories(categories, {
135
+ order: order,
136
+ orderBy: orderBy,
137
+ showCurrent: showCurrent,
138
+ depth: depth,
139
+ amount: amount
140
+ }, page, url_for),
141
+ list = _prepareCategories.categories,
142
+ hasMore = _prepareCategories.hasMore;
190
143
  return {
191
144
  showCount: showCount,
192
- categories: hasMore ? list.slice(0, amount) : list,
145
+ categories: list,
193
146
  title: _p('common.category', Infinity),
194
147
  moreUrl: hasMore ? url_for('categories/') : null,
195
148
  moreTitle: translate(__, 'widget.more', 'More')
@@ -0,0 +1,94 @@
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
+ * Responsive GitHub contribution calendar widget.
19
+ * @module view/widget/github_calendar
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/i18n'),
26
+ translate = _require3.translate;
27
+
28
+ /**
29
+ * Render the calendar shell. Themes load asset/js/github-calendar.js, call
30
+ * window.HexoGithubCalendar.init() after each page render, and provide calendar styles.
31
+ *
32
+ * @example
33
+ * <GithubCalendar username="octocat" title="GitHub Contributions"
34
+ * loading="Loading contributions…" error="Could not load contributions." />
35
+ */
36
+ var GithubCalendar = /*#__PURE__*/function (_Component) {
37
+ function GithubCalendar() {
38
+ _classCallCheck(this, GithubCalendar);
39
+ return _callSuper(this, GithubCalendar, arguments);
40
+ }
41
+ _inherits(GithubCalendar, _Component);
42
+ return _createClass(GithubCalendar, [{
43
+ key: "render",
44
+ value: function render() {
45
+ var _this$props = this.props,
46
+ username = _this$props.username,
47
+ title = _this$props.title,
48
+ color = _this$props.color,
49
+ loading = _this$props.loading,
50
+ error = _this$props.error;
51
+ if (!username) {
52
+ return null;
53
+ }
54
+ return (0, _inferno.createVNode)(1, "div", "card widget", (0, _inferno.createVNode)(1, "div", "card-content", [(0, _inferno.createVNode)(1, "h3", "menu-label", title, 0), (0, _inferno.createVNode)(1, "div", "github-calendar-chart", [(0, _inferno.createVNode)(1, "p", "github-calendar-status is-size-7", loading, 0, {
55
+ "role": "status"
56
+ }), (0, _inferno.createVNode)(1, "a", "github-calendar-link", (0, _inferno.createVNode)(1, "span", "github-calendar-grid"), 2, {
57
+ "href": 'https://github.com/' + username + '?tab=overview',
58
+ "target": "_blank",
59
+ "rel": "noopener noreferrer",
60
+ "aria-label": title
61
+ }), (0, _inferno.createVNode)(1, "noscript", null, (0, _inferno.createVNode)(1, "a", null, title, 0, {
62
+ "href": 'https://github.com/' + username
63
+ }), 2)], 4, {
64
+ "data-username": username,
65
+ "data-error": error,
66
+ "style": color ? {
67
+ '--github-calendar-color': '#' + color
68
+ } : null
69
+ })], 4), 2, {
70
+ "data-type": "github_calendar"
71
+ });
72
+ }
73
+ }]);
74
+ }(Component);
75
+ /** Cacheable calendar using the theme's translations, with English fallbacks. */
76
+ GithubCalendar.Cacheable = cacheComponent(GithubCalendar, 'widget.github_calendar', function (props) {
77
+ var _props$widget = props.widget,
78
+ widget = _props$widget === void 0 ? {} : _props$widget,
79
+ _props$helper = props.helper,
80
+ helper = _props$helper === void 0 ? {} : _props$helper;
81
+ var username = typeof widget.username === 'string' ? widget.username.trim() : '';
82
+ if (!/^[a-z\d](?:[a-z\d-]{0,37}[a-z\d])?$/i.test(username)) {
83
+ return null;
84
+ }
85
+ var color = typeof widget.color === 'string' ? widget.color.replace(/^#/, '') : '';
86
+ return {
87
+ username: username,
88
+ title: widget.title || translate(helper.__, 'widget.github_calendar', 'GitHub Contributions'),
89
+ color: /^[a-f\d]{6}$/i.test(color) ? color : null,
90
+ loading: translate(helper.__, 'widget.github_calendar_loading', 'Loading contributions…'),
91
+ error: translate(helper.__, 'widget.github_calendar_error', 'Could not load contributions. Open GitHub to view them.')
92
+ };
93
+ });
94
+ module.exports = GithubCalendar;