From 3973d1886b8e7cc7c33629662e86e8b7f3921699 Mon Sep 17 00:00:00 2001 From: seven Date: Sat, 11 Aug 2018 15:11:28 +0800 Subject: [PATCH 1/3] hide single post or posts in specific categories on the home page --- _config.yml | 10 ++++++++++ layout/index.swig | 28 +++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/_config.yml b/_config.yml index a89302b92c..e01ebc10f2 100644 --- a/_config.yml +++ b/_config.yml @@ -332,6 +332,16 @@ post_copyright: enable: false license: CC BY-NC-SA 4.0 +# Hide single post or posts in specific categories on the home page +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..1ca805b43d 100644 --- a/layout/index.swig +++ b/layout/index.swig @@ -11,7 +11,33 @@ {% block content %}
{% for post in page.posts %} - {{ post_template.render(post, true) }} + {% set hide = false %} + + {% if theme.hide.hide_post %} + {% if post.hide %} + {% set hide = true %} + {% endif %} + {% endif %} + + {% if theme.hide.hide_categories.enable && !hide %} + {% 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 %} {% endfor %}
From 98696b7b7059ef2dbfb93058fcbc70c96d4925a4 Mon Sep 17 00:00:00 2001 From: seven Date: Sat, 11 Aug 2018 18:52:30 +0800 Subject: [PATCH 2/3] add some comments in '_config.yml' about how to use the item 'hide' --- _config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/_config.yml b/_config.yml index e01ebc10f2..f7e2e6bca6 100644 --- a/_config.yml +++ b/_config.yml @@ -333,6 +333,8 @@ post_copyright: license: CC BY-NC-SA 4.0 # 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: From cbb6baa01b4c40a7017182133831d73536c5428a Mon Sep 17 00:00:00 2001 From: Seven Date: Thu, 27 Dec 2018 15:04:49 +0800 Subject: [PATCH 3/3] just hide post on the first page --- layout/index.swig | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/layout/index.swig b/layout/index.swig index 1ca805b43d..6c2308ce07 100644 --- a/layout/index.swig +++ b/layout/index.swig @@ -11,31 +11,29 @@ {% block content %}
{% for post in page.posts %} - {% set hide = false %} - - {% if theme.hide.hide_post %} - {% if post.hide %} + {% 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 %} - {% endif %} - - {% if theme.hide.hide_categories.enable && !hide %} - {% 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 %} + {% if !hide %} + {{ post_template.render(post, true) }} + {% endif %} + {% else %} {{ post_template.render(post, true) }} {% endif %} {% endfor %} @@ -46,4 +44,4 @@ {% block sidebar %} {{ sidebar_template.render(false) }} -{% endblock %} +{% endblock %} \ No newline at end of file