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.
@@ -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/i18n'),
26
+ translate = _require3.translate;
25
27
 
26
28
  /**
27
29
  * Convert a Hexo language code into a Moment.js locale name.
@@ -70,12 +72,18 @@ var Archives = /*#__PURE__*/function (_Component) {
70
72
  var _this$props = this.props,
71
73
  items = _this$props.items,
72
74
  title = _this$props.title,
73
- showCount = _this$props.showCount;
74
- return (0, _inferno.createVNode)(1, "div", "card widget", (0, _inferno.createVNode)(1, "div", "card-content", (0, _inferno.createVNode)(1, "div", "menu", [(0, _inferno.createVNode)(1, "h3", "menu-label", title, 0), (0, _inferno.createVNode)(1, "ul", "menu-list", items.map(function (archive) {
75
+ showCount = _this$props.showCount,
76
+ moreUrl = _this$props.moreUrl,
77
+ moreTitle = _this$props.moreTitle;
78
+ return (0, _inferno.createVNode)(1, "div", "card widget", (0, _inferno.createVNode)(1, "div", "card-content", (0, _inferno.createVNode)(1, "div", "menu", [(0, _inferno.createVNode)(1, "h3", "menu-label", title, 0), (0, _inferno.createVNode)(1, "ul", "menu-list", [items.map(function (archive) {
75
79
  return (0, _inferno.createVNode)(1, "li", null, (0, _inferno.createVNode)(1, "a", "level is-mobile", [(0, _inferno.createVNode)(1, "span", "level-start", (0, _inferno.createVNode)(1, "span", "level-item", archive.name, 0), 2), showCount ? (0, _inferno.createVNode)(1, "span", "level-end", (0, _inferno.createVNode)(1, "span", "level-item tag", archive.count, 0), 2) : null], 0, {
76
80
  "href": archive.url
77
81
  }), 2);
78
- }), 0)], 4), 2), 2, {
82
+ }), moreUrl ? (0, _inferno.createVNode)(1, "li", null, (0, _inferno.createVNode)(1, "a", "level is-mobile", [(0, _inferno.createVNode)(1, "span", "level-start", (0, _inferno.createVNode)(1, "span", "level-item", moreTitle, 0), 2), (0, _inferno.createVNode)(1, "span", "level-end", (0, _inferno.createVNode)(1, "span", "level-item icon is-small", (0, _inferno.createVNode)(1, "i", "fas fa-chevron-right"), 2, {
83
+ "aria-hidden": "true"
84
+ }), 2)], 4, {
85
+ "href": moreUrl
86
+ }), 2) : null], 0)], 4), 2), 2, {
79
87
  "data-type": "archives"
80
88
  });
81
89
  }
@@ -123,9 +131,11 @@ Archives.Cacheable = cacheComponent(Archives, 'widget.archives', function (props
123
131
  _widget$showCount = widget.showCount,
124
132
  showCount = _widget$showCount === void 0 ? true : _widget$showCount,
125
133
  _widget$format = widget.format,
126
- format = _widget$format === void 0 ? null : _widget$format;
134
+ format = _widget$format === void 0 ? null : _widget$format,
135
+ amount = widget.amount;
127
136
  var url_for = helper.url_for,
128
- _p = helper._p;
137
+ _p = helper._p,
138
+ __ = helper.__;
129
139
  var posts = site.posts.sort('date', order);
130
140
  if (!posts.length) {
131
141
  return null;
@@ -165,8 +175,11 @@ Archives.Cacheable = cacheComponent(Archives, 'widget.archives', function (props
165
175
  }
166
176
  return url_for(url);
167
177
  };
178
+
179
+ // Link to the archive page when some of the archives are not shown
180
+ var hasMore = amount > 0 && data.length > amount;
168
181
  return {
169
- items: data.map(function (item) {
182
+ items: (hasMore ? data.slice(0, amount) : data).map(function (item) {
170
183
  return {
171
184
  name: item.name,
172
185
  count: item.count,
@@ -174,7 +187,9 @@ Archives.Cacheable = cacheComponent(Archives, 'widget.archives', function (props
174
187
  };
175
188
  }),
176
189
  title: _p('common.archive', Infinity),
177
- showCount: showCount
190
+ showCount: showCount,
191
+ moreUrl: hasMore ? url_for("".concat(config.archive_dir, "/")) : null,
192
+ moreTitle: translate(__, 'widget.more', 'More')
178
193
  };
179
194
  });
180
195
  module.exports = Archives;
@@ -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/i18n'),
26
+ translate = _require3.translate;
25
27
 
26
28
  /**
27
29
  * Categories widget JSX component.
@@ -66,8 +68,14 @@ var Categories = /*#__PURE__*/function (_Component) {
66
68
  var _this$props = this.props,
67
69
  title = _this$props.title,
68
70
  showCount = _this$props.showCount,
69
- categories = _this$props.categories;
70
- return (0, _inferno.createVNode)(1, "div", "card widget", (0, _inferno.createVNode)(1, "div", "card-content", (0, _inferno.createVNode)(1, "div", "menu", [(0, _inferno.createVNode)(1, "h3", "menu-label", title, 0), (0, _inferno.createVNode)(1, "ul", "menu-list", this.renderList(categories, showCount), 0)], 4), 2), 2, {
71
+ categories = _this$props.categories,
72
+ moreUrl = _this$props.moreUrl,
73
+ moreTitle = _this$props.moreTitle;
74
+ return (0, _inferno.createVNode)(1, "div", "card widget", (0, _inferno.createVNode)(1, "div", "card-content", (0, _inferno.createVNode)(1, "div", "menu", [(0, _inferno.createVNode)(1, "h3", "menu-label", title, 0), (0, _inferno.createVNode)(1, "ul", "menu-list", [this.renderList(categories, showCount), moreUrl ? (0, _inferno.createVNode)(1, "li", null, (0, _inferno.createVNode)(1, "a", "level is-mobile", [(0, _inferno.createVNode)(1, "span", "level-start", (0, _inferno.createVNode)(1, "span", "level-item", moreTitle, 0), 2), (0, _inferno.createVNode)(1, "span", "level-end", (0, _inferno.createVNode)(1, "span", "level-item icon is-small", (0, _inferno.createVNode)(1, "i", "fas fa-chevron-right"), 2, {
75
+ "aria-hidden": "true"
76
+ }), 2)], 4, {
77
+ "href": moreUrl
78
+ }), 2) : null], 0)], 4), 2), 2, {
71
79
  "data-type": "categories"
72
80
  });
73
81
  }
@@ -113,9 +121,11 @@ Categories.Cacheable = cacheComponent(Categories, 'widget.categories', function
113
121
  _widget$showCurrent = widget.showCurrent,
114
122
  showCurrent = _widget$showCurrent === void 0 ? false : _widget$showCurrent,
115
123
  _widget$showCount = widget.showCount,
116
- showCount = _widget$showCount === void 0 ? true : _widget$showCount;
124
+ showCount = _widget$showCount === void 0 ? true : _widget$showCount,
125
+ amount = widget.amount;
117
126
  var url_for = helper.url_for,
118
- _p = helper._p;
127
+ _p = helper._p,
128
+ __ = helper.__;
119
129
  if (!categories || !categories.length) {
120
130
  return null;
121
131
  }
@@ -163,10 +173,16 @@ Categories.Cacheable = cacheComponent(Categories, 'widget.categories', function
163
173
  };
164
174
  });
165
175
  }
176
+
177
+ // Only limit the top-level categories, and link to the category page when some are not shown
178
+ var list = hierarchicalList(0);
179
+ var hasMore = amount > 0 && list.length > amount;
166
180
  return {
167
181
  showCount: showCount,
168
- categories: hierarchicalList(0),
169
- title: _p('common.category', Infinity)
182
+ categories: hasMore ? list.slice(0, amount) : list,
183
+ title: _p('common.category', Infinity),
184
+ moreUrl: hasMore ? url_for('categories/') : null,
185
+ moreTitle: translate(__, 'widget.more', 'More')
170
186
  };
171
187
  });
172
188
  module.exports = Categories;
@@ -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/i18n'),
26
+ translate = _require3.translate;
25
27
 
26
28
  /**
27
29
  * Tags widget JSX component.
@@ -50,12 +52,18 @@ var Tags = /*#__PURE__*/function (_Component) {
50
52
  var _this$props = this.props,
51
53
  tags = _this$props.tags,
52
54
  title = _this$props.title,
53
- showCount = _this$props.showCount;
54
- return (0, _inferno.createVNode)(1, "div", "card widget", (0, _inferno.createVNode)(1, "div", "card-content", (0, _inferno.createVNode)(1, "div", "menu", [(0, _inferno.createVNode)(1, "h3", "menu-label", title, 0), (0, _inferno.createVNode)(1, "div", "field is-grouped is-grouped-multiline", tags.map(function (tag) {
55
+ showCount = _this$props.showCount,
56
+ moreUrl = _this$props.moreUrl,
57
+ moreTitle = _this$props.moreTitle;
58
+ return (0, _inferno.createVNode)(1, "div", "card widget", (0, _inferno.createVNode)(1, "div", "card-content", (0, _inferno.createVNode)(1, "div", "menu", [(0, _inferno.createVNode)(1, "h3", "menu-label", title, 0), (0, _inferno.createVNode)(1, "div", "field is-grouped is-grouped-multiline", [tags.map(function (tag) {
55
59
  return (0, _inferno.createVNode)(1, "div", "control", (0, _inferno.createVNode)(1, "a", "tags has-addons", [(0, _inferno.createVNode)(1, "span", "tag", tag.name, 0), showCount ? (0, _inferno.createVNode)(1, "span", "tag", tag.count, 0) : null], 0, {
56
60
  "href": tag.url
57
61
  }), 2);
58
- }), 0)], 4), 2), 2, {
62
+ }), moreUrl ? (0, _inferno.createVNode)(1, "div", "control", (0, _inferno.createVNode)(1, "a", "tags has-addons", (0, _inferno.createVNode)(1, "span", "tag", [(0, _inferno.createVNode)(1, "span", null, moreTitle, 0), (0, _inferno.createVNode)(1, "span", "icon is-small", (0, _inferno.createVNode)(1, "i", "fas fa-chevron-right"), 2, {
63
+ "aria-hidden": "true"
64
+ })], 4), 2, {
65
+ "href": moreUrl
66
+ }), 2) : null], 0)], 4), 2), 2, {
59
67
  "data-type": "tags"
60
68
  });
61
69
  }
@@ -94,19 +102,24 @@ Tags.Cacheable = cacheComponent(Tags, 'widget.tags', function (props) {
94
102
  show_count = _widget$show_count === void 0 ? true : _widget$show_count;
95
103
  var tags = props.tags || props.site.tags;
96
104
  var url_for = helper.url_for,
97
- _p = helper._p;
105
+ _p = helper._p,
106
+ __ = helper.__;
98
107
  if (!tags || !tags.length) {
99
108
  return null;
100
109
  }
101
110
  tags = tags.sort(order_by).filter(function (tag) {
102
111
  return tag.length;
103
112
  });
104
- if (amount) {
113
+ // Link to the tag page when some of the tags are not shown
114
+ var hasMore = amount > 0 && tags.length > amount;
115
+ if (hasMore) {
105
116
  tags = tags.limit(amount);
106
117
  }
107
118
  return {
108
119
  showCount: show_count,
109
120
  title: _p('common.tag', Infinity),
121
+ moreUrl: hasMore ? url_for('tags/') : null,
122
+ moreTitle: translate(__, 'widget.more', 'More'),
110
123
  tags: tags.map(function (tag) {
111
124
  return {
112
125
  name: tag.name,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hexo-component-inferno",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "A collection of Inferno.js layout components and utility scripts for Hexo",
5
5
  "main": "lib/index.js",
6
6
  "repository": "https://github.com/ppoffice/hexo-component-inferno",