Skip to content

Commit

Permalink
Revert "Avoid recalculating the number of tags and categories (theme-…
Browse files Browse the repository at this point in the history
…next#954)" (theme-next#969)

This reverts commit a8e2aef.
  • Loading branch information
jiangtj authored Jul 12, 2019
1 parent 8dd8f17 commit 4b19aa9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
4 changes: 2 additions & 2 deletions layout/_macro/menu/menu-badge.swig
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

{% set badges = {
archives: site.posts.length,
categories: theme.visibleCategories,
tags: theme.visibleTags }
categories: site.categories.length,
tags: site.tags.length }
%}
{% for menu, count in badges %}
{% if name == menu %}
Expand Down
16 changes: 12 additions & 4 deletions layout/_macro/sidebar.swig
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</div>
{% endif %}

{% if theme.visibleCategories > 0 %}
{% if site.categories.length > 0 %}
{% set categoriesPageQuery = site.pages.find({type: 'categories'}, {lean: true}) %}
{% set hasCategoriesPage = categoriesPageQuery.length > 0 %}
<div class="site-state-item site-state-categories">
Expand All @@ -61,13 +61,17 @@
<a href="{{ url_for(config.category_dir) + '/' }}">
{% endif %}
{% endif %}
<span class="site-state-item-count">{{ theme.visibleCategories }}</span>
{% set visibleCategories = 0 %}
{% for cat in site.categories %}
{% if cat.length %}{% set visibleCategories += 1 %}{% endif %}
{% endfor %}
<span class="site-state-item-count">{{ visibleCategories }}</span>
<span class="site-state-item-name">{{ __('state.categories') }}</span>
{% if hasCategoriesPage %}</a>{% endif %}
</div>
{% endif %}

{% if theme.visibleTags > 0 %}
{% if site.tags.length > 0 %}
{% set tagsPageQuery = site.pages.find({type: 'tags'}, {lean: true}) %}
{% set hasTagsPage = tagsPageQuery.length > 0 %}
<div class="site-state-item site-state-tags">
Expand All @@ -78,7 +82,11 @@
<a href="{{ url_for(config.tag_dir) + '/' }}">
{% endif %}
{% endif %}
<span class="site-state-item-count">{{ theme.visibleTags }}</span>
{% set visibleTags = 0 %}
{% for tag in site.tags %}
{% if tag.length %}{% set visibleTags += 1 %}{% endif %}
{% endfor %}
<span class="site-state-item-count">{{ visibleTags }}</span>
<span class="site-state-item-name">{{ __('state.tags') }}</span>
{% if hasTagsPage %}</a>{% endif %}
</div>
Expand Down
16 changes: 14 additions & 2 deletions layout/page.swig
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@
{% if page.type === 'tags' %}
<div class="tag-cloud">
<div class="tag-cloud-title">
{{ _p('counter.tag_cloud', theme.visibleTags) }}
{% set visibleTags = 0 %}
{% for tag in site.tags %}
{% if tag.length %}
{% set visibleTags += 1 %}
{% endif %}
{% endfor %}
{{ _p('counter.tag_cloud', visibleTags) }}
</div>
<div class="tag-cloud-tags">
{% if not theme.tagcloud %}
Expand All @@ -46,7 +52,13 @@
{% elif page.type === 'categories' %}
<div class="category-all-page">
<div class="category-all-title">
{{ _p('counter.categories', theme.visibleCategories) }}
{% set visibleCategories = 0 %}
{% for cat in site.categories %}
{% if cat.length %}
{% set visibleCategories += 1 %}
{% endif %}
{% endfor %}
{{ _p('counter.categories', visibleCategories) }}
</div>
<div class="category-all">
{{ list_categories() }}
Expand Down
16 changes: 0 additions & 16 deletions scripts/merge-configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,4 @@ hexo.on('generateBefore', function() {
// Add filter type `theme_inject`
require('./injects')(hexo);

// Fix an issue about the categories/tags count.
let visibleTags = 0;
hexo.locals.get('tags').forEach((tag) => {
if (tag.length) {
visibleTags += 1;
}
});
hexo.theme.config.visibleTags = visibleTags;
let visibleCategories = 0;
hexo.locals.get('categories').forEach((categorie) => {
if (categorie.length) {
visibleCategories += 1;
}
});
hexo.theme.config.visibleCategories = visibleCategories;

});

0 comments on commit 4b19aa9

Please sign in to comment.