From 26d682cfa28a5796fd0c9381480bbc40056ca2f6 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Wed, 17 Apr 2024 12:30:16 +0800 Subject: [PATCH] Add post_count helper --- layout/_macro/post-collapse.njk | 2 +- scripts/helpers/engine.js | 4 ++++ source/css/_common/components/post/post-collapse.styl | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/layout/_macro/post-collapse.njk b/layout/_macro/post-collapse.njk index 4c391194d..9bffbedc5 100644 --- a/layout/_macro/post-collapse.njk +++ b/layout/_macro/post-collapse.njk @@ -7,7 +7,7 @@ {%- if year !== current_year %} {%- set current_year = year %}
- {{ current_year }} + {{ current_year }}{% if is_archive() %}{{ post_count(year) }}{% endif %}
{%- endif %} diff --git a/scripts/helpers/engine.js b/scripts/helpers/engine.js index 7f6fbe973..949bdcff7 100644 --- a/scripts/helpers/engine.js +++ b/scripts/helpers/engine.js @@ -92,6 +92,10 @@ hexo.extend.helper.register('post_edit', function(src) { }); }); +hexo.extend.helper.register('post_count', function(year) { + return this.site.posts.filter(post => this.date(post.date, 'YYYY') === year).count(); +}); + hexo.extend.helper.register('gitalk_md5', function(path) { const str = this.url_for(path); return crypto.createHash('md5').update(str).digest('hex'); diff --git a/source/css/_common/components/post/post-collapse.styl b/source/css/_common/components/post/post-collapse.styl index a4b5719a2..888d7ba05 100644 --- a/source/css/_common/components/post/post-collapse.styl +++ b/source/css/_common/components/post/post-collapse.styl @@ -29,6 +29,11 @@ margin: 60px 0; position: relative; + .collection-year-count { + font-size: $font-size-smallest; + badge(); + } + &::before { background: $grey; margin-left: -4px;