mirror of
https://github.com/KivotosRailway/website.git
synced 2026-11-03 19:07:56 +09:00
14 lines
484 B
JavaScript
14 lines
484 B
JavaScript
const moment = require('moment')
|
|
|
|
hexo.extend.helper.register('getArchiveLength', function (type) {
|
|
if (type !== 'year' && type !== 'month') {
|
|
type = 'year';
|
|
}
|
|
const posts = this.site.posts.sort('-date').data
|
|
let archive = {}
|
|
for (const post of posts) {
|
|
const postdate = type === 'year' ? moment(post.date).format('YYYY') : moment(post.date).format('YYYY/MM');
|
|
archive[postdate] = (archive[postdate] || 0) + 1;
|
|
}
|
|
return archive;
|
|
}); |