From 5b27222b8670c5e78a0c096a0017caa48a4261de Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Mon, 13 Apr 2020 20:05:27 +0800 Subject: [PATCH] Improve the layout of Categories. --- tabs/categories.md | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/tabs/categories.md b/tabs/categories.md index c720ff5..504a2fe 100644 --- a/tabs/categories.md +++ b/tabs/categories.md @@ -13,17 +13,19 @@ title: Categories {% for category in sort_categories %} {% assign category_name = category | first %} {% assign posts_of_category = category | last %} - {% assign first_post = posts_of_category[0] %} + {% assign first_post = posts_of_category | first %} {% if category_name == first_post.categories[0] %} - {% assign sub_categories = "" %} + {% assign sub_categories = "" | split: "" %} + {% for post in posts_of_category %} - {% if post.categories.size > 1 %} - {% assign sub_categories = sub_categories | append: post.categories[1] | append: "|" %} - {% endif %} + {% assign second_category = post.categories[1] %} + {% unless sub_categories contains second_category %} + {% assign sub_categories = sub_categories | push: second_category %} + {% endunless %} {% endfor %} - {% assign sub_categories = sub_categories | split: "|" | uniq | sort %} + {% assign sub_categories = sub_categories | sort %} {% assign sub_categories_size = sub_categories | size %}