diff --git a/_config.yml b/_config.yml index 9a3f968249..7eeb2efaf5 100644 --- a/_config.yml +++ b/_config.yml @@ -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: diff --git a/layout/index.swig b/layout/index.swig index 9fd359f078..6c2308ce07 100644 --- a/layout/index.swig +++ b/layout/index.swig @@ -11,7 +11,31 @@ {% block content %}
{% 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 %}
@@ -20,4 +44,4 @@ {% block sidebar %} {{ sidebar_template.render(false) }} -{% endblock %} +{% endblock %} \ No newline at end of file