mirror of
https://codeberg.org/fediverse/fediparty.git
synced 2024-10-31 22:27:21 +00:00
Avoid dependency on lodash
This commit re-implements `_.groupBy`. The call to `_.sortBy` was unnecessary and was thus removed entirely. This should simplify migration to newer releases of Hexo that no longer include lodash.
This commit is contained in:
parent
8663e47585
commit
1304dbeb25
|
@ -17,7 +17,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="one-tag-list">
|
<div class="one-tag-list">
|
||||||
<span class="tag__text"><%= title %></span>
|
<span class="tag__text"><%= title %></span>
|
||||||
<% const groupObj = _.groupBy(page.posts.toArray(), function(p) {return -p.date.format('YYYY')}) %>
|
<% const groupObj = groupBy(page.posts.toArray(), function(p) {return -p.date.format('YYYY')}) %>
|
||||||
<% for (let year in groupObj){ %>
|
<% for (let year in groupObj){ %>
|
||||||
<h3 class="tags__year"><%- -year %></h3>
|
<h3 class="tags__year"><%- -year %></h3>
|
||||||
<ul class="tags__list">
|
<ul class="tags__list">
|
||||||
|
|
|
@ -10,11 +10,11 @@ layout: layout
|
||||||
<% }) %>
|
<% }) %>
|
||||||
</div>
|
</div>
|
||||||
<div class="one-tag-list">
|
<div class="one-tag-list">
|
||||||
<% const groupObj = _.groupBy(site.posts.sort('date', -1).toArray(), function(p){return -p.date.format('YYYY')}) %>
|
<% const groupObj = groupBy(site.posts.sort('date', -1).toArray(), function(p){return -p.date.format('YYYY')}) %>
|
||||||
<% for (let year in groupObj){ %>
|
<% for (let year in groupObj){ %>
|
||||||
<h3 class="tags__year"><%- -year %></h3>
|
<h3 class="tags__year"><%- -year %></h3>
|
||||||
<ul class="tags__list">
|
<ul class="tags__list">
|
||||||
<%- partial('_partial/taglist', {posts: _.sortBy(groupObj[year], 'date').reverse()}) %>
|
<%- partial('_partial/taglist', {posts: groupObj[year]}) %>
|
||||||
</ul>
|
</ul>
|
||||||
<% } %>
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -5,6 +5,7 @@ hexo.extend.helper.register('get_langs', getLangs);
|
||||||
hexo.extend.helper.register('switch_lang', switchLang);
|
hexo.extend.helper.register('switch_lang', switchLang);
|
||||||
hexo.extend.helper.register('getPath', getPath);
|
hexo.extend.helper.register('getPath', getPath);
|
||||||
hexo.extend.helper.register('stripHTTPS', stripHTTPS);
|
hexo.extend.helper.register('stripHTTPS', stripHTTPS);
|
||||||
|
hexo.extend.helper.register('groupBy', groupBy);
|
||||||
|
|
||||||
function isRoot() {
|
function isRoot() {
|
||||||
const lang = this.page.lang;
|
const lang = this.page.lang;
|
||||||
|
@ -36,3 +37,15 @@ function getPath() {
|
||||||
function stripHTTPS(x) {
|
function stripHTTPS(x) {
|
||||||
return x.split('://')[1];
|
return x.split('://')[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function groupBy(arr, fn) {
|
||||||
|
let result = {};
|
||||||
|
for (const element of arr) {
|
||||||
|
const key = fn(element);
|
||||||
|
if (!(key in result)) {
|
||||||
|
result[key] = new Array();
|
||||||
|
}
|
||||||
|
result[key].push(element);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue