Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hide single post or posts in specific categories on the home page #385

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,18 @@ related_posts:
#isImage: false
#isExcerpt: false

# Hide single post or posts in specific categories on the home page
# If `hide_post` is `true`, you need to add `hide: true` in your post which you want to hide on the home page.
# If you enabled the item `hide_categories`, you need just list the categories which you want to hide on the home page under the item `categories`.
hide:
hide_post: false
hide_categories:
enable: false
categories:
# - categorie1
# - categorie2


# Post edit
# Dependencies: https://github.com/hexojs/hexo-deployer-git
post_edit:
Expand Down
28 changes: 26 additions & 2 deletions layout/index.swig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,31 @@
{% block content %}
<section id="posts" class="posts-expand">
{% for post in page.posts %}
{{ post_template.render(post, true) }}
{% if is_home() && page.current === 1 %}
{% set hide = false %}
{% if theme.hide.hide_post && post.hide %}
{% set hide = true %}
{% elif theme.hide.hide_categories.enable %}
{% for cat in post.categories %}
{% if !hide %}
{% for categorie in cat %}
{% if !hide %}
{% for item in theme.hide.hide_categories.categories %}
{% if !hide && item == categorie %}
{% set hide = true %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{% if !hide %}
{{ post_template.render(post, true) }}
{% endif %}
{% else %}
{{ post_template.render(post, true) }}
{% endif %}
{% endfor %}
</section>

Expand All @@ -20,4 +44,4 @@

{% block sidebar %}
{{ sidebar_template.render(false) }}
{% endblock %}
{% endblock %}