Skip to content

Commit

Permalink
Add post_count helper
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Apr 17, 2024
1 parent 3d34a11 commit 26d682c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion layout/_macro/post-collapse.njk
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{%- if year !== current_year %}
{%- set current_year = year %}
<div class="collection-year">
<span class="collection-header">{{ current_year }}</span>
<span class="collection-header">{{ current_year }}{% if is_archive() %}<span class="collection-year-count">{{ post_count(year) }}</span>{% endif %}</span>
</div>
{%- endif %}

Expand Down
4 changes: 4 additions & 0 deletions scripts/helpers/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
5 changes: 5 additions & 0 deletions source/css/_common/components/post/post-collapse.styl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
margin: 60px 0;
position: relative;

.collection-year-count {
font-size: $font-size-smallest;
badge();
}

&::before {
background: $grey;
margin-left: -4px;
Expand Down

0 comments on commit 26d682c

Please sign in to comment.