From e27825d3ebf8956fbdecc6e40b5729b1462c63bf Mon Sep 17 00:00:00 2001
From: Cotes Chung <11371340+cotes2020@users.noreply.github.com>
Date: Fri, 4 Dec 2020 14:18:25 +0800
Subject: [PATCH] Improve JS/CSS selector
Separate layout from tabs, and more friendly to tabs rename (#187)
---
_includes/css-selector.html | 47 ++++------------
_includes/js-selector.html | 37 +++++--------
_layouts/archives.html | 41 ++++++++++++++
_layouts/categories.html | 105 ++++++++++++++++++++++++++++++++++++
_layouts/tags.html | 26 +++++++++
_tabs/archives.md | 38 +------------
_tabs/categories.md | 102 +----------------------------------
_tabs/tags.md | 27 +---------
8 files changed, 196 insertions(+), 227 deletions(-)
create mode 100644 _layouts/archives.html
create mode 100644 _layouts/categories.html
create mode 100644 _layouts/tags.html
diff --git a/_includes/css-selector.html b/_includes/css-selector.html
index 965071b..b04be9c 100644
--- a/_includes/css-selector.html
+++ b/_includes/css-selector.html
@@ -6,50 +6,21 @@
MIT Licensed
-->
-{% if page.layout == 'home' %}
-
-
-{% elsif page.layout == 'page' %}
+{% if page.layout == 'category' or page.layout == 'tag' %}
+ {% assign style = 'category-tag' %}
+{% else %}
+ {% assign style = page.layout %}
+{% endif %}
- {% if page.collection == 'tabs' and page.title != 'About' %}
+{% assign src = style | prepend: '/assets/css/' | append: '.css' | relative_url %}
- {% if page.title == 'Categories' %}
-
-
-
- {% elsif page.title == 'Tags' %}
-
-
-
- {% elsif page.title == 'Archives'%}
-
-
-
- {% endif %}
-
- {% else %}
-
-
-
-
- {% endif %}
-
-{% elsif page.layout == 'category' or page.layout == 'tag' %}
-
-
-
-
-{% elsif page.layout == 'post' %}
-
-
-
+
+
+{% if page.layout == 'post' %}
{% if site.toc and page.toc %}
-
-
{% endif %}
-
{% endif %}
diff --git a/_includes/js-selector.html b/_includes/js-selector.html
index 622de8f..a892e2a 100644
--- a/_includes/js-selector.html
+++ b/_includes/js-selector.html
@@ -6,34 +6,21 @@
MIT Licensed
-->
-{% if page.layout == 'home' %}
-
-
-
-{% elsif page.layout == 'post' %}
-
-
-
- {% if page.math %}
-
-
-
- {% endif %}
-
-{% elsif page.layout == 'page' %}
-
- {% if page.title == 'Categories' and page.collection == 'tabs' %}
-
- {% else %}
-
- {% endif %}
-
+{% if page.layout == 'home' or page.layout == 'post' or page.layout == 'categories' %}
+ {% assign js = page.layout %}
{% else %}
-
-
-
+ {% assign js = "page" %}
{% endif %}
+{% assign js_src = js | prepend: '/assets/js/' | append: '.min.js' | relative_url %}
+
+
+
+{% if page.math %}
+
+
+
+{% endif %}
{% if jekyll.environment == 'production' %}
diff --git a/_layouts/archives.html b/_layouts/archives.html
new file mode 100644
index 0000000..ea4f0b5
--- /dev/null
+++ b/_layouts/archives.html
@@ -0,0 +1,41 @@
+---
+layout: page
+
+# The Archives of posts.
+# v2.0
+# https://github.com/cotes2020/jekyll-theme-chirpy
+# © 2017-2019 Cotes Chung
+# MIT License
+---
+
+
+
+{% for post in site.posts %}
+ {% capture this_year %}{{ post.date | date: "%Y" }}{% endcapture %}
+ {% capture pre_year %}{{ post.previous.date | date: "%Y" }}{% endcapture %}
+ {% if forloop.first %}
+ {% assign last_day = "" %}
+ {% assign last_month = "" %}
+
{{this_year}}
+
+ {% endif %}
+ -
+
+ {% capture this_day %}{{ post.date | date: "%d" }}{% endcapture %}
+ {% capture this_month %}{{ post.date | date: "%b" }}{% endcapture %}
+
{{ this_day }}
+
{{ this_month }}
+
{{ post.title }}
+
+
+ {% if forloop.last %}
+
+ {% elsif this_year != pre_year %}
+
+
{{pre_year}}
+
+ {% assign last_day = "" %}
+ {% assign last_month = "" %}
+ {% endif %}
+{% endfor %}
+
diff --git a/_layouts/categories.html b/_layouts/categories.html
new file mode 100644
index 0000000..1786cf1
--- /dev/null
+++ b/_layouts/categories.html
@@ -0,0 +1,105 @@
+---
+layout: page
+
+# All the Categories of posts
+# v2.0
+# https://github.com/cotes2020/jekyll-theme-chirpy
+# © 2017-2019 Cotes Chung
+# MIT License
+---
+
+
+{% assign HEAD_PREFIX = "h_" %}
+{% assign LIST_PREFIX = "l_" %}
+
+{% assign group_index = 0 %}
+
+{% assign sort_categories = site.categories | sort %}
+
+{% for category in sort_categories %}
+ {% assign category_name = category | first %}
+ {% assign posts_of_category = category | last %}
+ {% assign first_post = posts_of_category | first %}
+
+ {% if category_name == first_post.categories[0] %}
+ {% assign sub_categories = "" | split: "" %}
+
+ {% for post in posts_of_category %}
+ {% assign second_category = post.categories[1] %}
+ {% if second_category %}
+ {% unless sub_categories contains second_category %}
+ {% assign sub_categories = sub_categories | push: second_category %}
+ {% endunless %}
+ {% endif %}
+ {% endfor %}
+
+ {% assign sub_categories = sub_categories | sort %}
+ {% assign sub_categories_size = sub_categories | size %}
+
+
+
+
+
+
+ {% if sub_categories_size > 0 %}
+
+
+ {% for sub_category in sub_categories %}
+ -
+
+ {{ sub_category }}
+ {% assign posts_size = site.categories[sub_category] | size %}
+ {{ posts_size }}
+ post{% if posts_size > 1 %}s{% endif %}
+
+
+ {% endfor %}
+
+
+ {% endif %}
+
+
+
+ {% assign group_index = group_index | plus: 1 %}
+
+ {% endif %}
+{% endfor %}
diff --git a/_layouts/tags.html b/_layouts/tags.html
new file mode 100644
index 0000000..5c7d632
--- /dev/null
+++ b/_layouts/tags.html
@@ -0,0 +1,26 @@
+---
+layout: page
+
+# All the Tags of posts.
+# v2.0
+# https://github.com/cotes2020/jekyll-theme-chirpy
+# © 2017-2019 Cotes Chung
+# MIT License
+---
+
+
diff --git a/_tabs/archives.md b/_tabs/archives.md
index e84cc1d..1b42e95 100644
--- a/_tabs/archives.md
+++ b/_tabs/archives.md
@@ -1,42 +1,6 @@
---
-title: Archives
+layout: archives
icon: fas fa-archive
order: 3
-
-# The Archives of posts.
-# v2.0
-# https://github.com/cotes2020/jekyll-theme-chirpy
-# © 2017-2019 Cotes Chung
-# MIT License
---
-
-{% for post in site.posts %}
- {% capture this_year %}{{ post.date | date: "%Y" }}{% endcapture %}
- {% capture pre_year %}{{ post.previous.date | date: "%Y" }}{% endcapture %}
- {% if forloop.first %}
- {% assign last_day = "" %}
- {% assign last_month = "" %}
-
{{this_year}}
-
- {% endif %}
- -
-
- {% capture this_day %}{{ post.date | date: "%d" }}{% endcapture %}
- {% capture this_month %}{{ post.date | date: "%b" }}{% endcapture %}
-
{{ this_day }}
-
{{ this_month }}
-
{{ post.title }}
-
-
- {% if forloop.last %}
-
- {% elsif this_year != pre_year %}
-
-
{{pre_year}}
-
- {% assign last_day = "" %}
- {% assign last_month = "" %}
- {% endif %}
-{% endfor %}
-
diff --git a/_tabs/categories.md b/_tabs/categories.md
index e1c7afc..3a23c29 100644
--- a/_tabs/categories.md
+++ b/_tabs/categories.md
@@ -1,106 +1,6 @@
---
+layout: categories
title: Categories
icon: fas fa-stream
order: 1
-
-# All the Categories of posts
-# v2.0
-# https://github.com/cotes2020/jekyll-theme-chirpy
-# © 2017-2019 Cotes Chung
-# MIT License
---
-
-{% assign HEAD_PREFIX = "h_" %}
-{% assign LIST_PREFIX = "l_" %}
-
-{% assign group_index = 0 %}
-
-{% assign sort_categories = site.categories | sort %}
-
-{% for category in sort_categories %}
- {% assign category_name = category | first %}
- {% assign posts_of_category = category | last %}
- {% assign first_post = posts_of_category | first %}
-
- {% if category_name == first_post.categories[0] %}
- {% assign sub_categories = "" | split: "" %}
-
- {% for post in posts_of_category %}
- {% assign second_category = post.categories[1] %}
- {% if second_category %}
- {% unless sub_categories contains second_category %}
- {% assign sub_categories = sub_categories | push: second_category %}
- {% endunless %}
- {% endif %}
- {% endfor %}
-
- {% assign sub_categories = sub_categories | sort %}
- {% assign sub_categories_size = sub_categories | size %}
-
-
-
-
-
-
- {% if sub_categories_size > 0 %}
-
-
- {% for sub_category in sub_categories %}
- -
-
- {{ sub_category }}
- {% assign posts_size = site.categories[sub_category] | size %}
- {{ posts_size }}
- post{% if posts_size > 1 %}s{% endif %}
-
-
- {% endfor %}
-
-
- {% endif %}
-
-
-
- {% assign group_index = group_index | plus: 1 %}
-
- {% endif %}
-{% endfor %}
diff --git a/_tabs/tags.md b/_tabs/tags.md
index c676761..53abc94 100644
--- a/_tabs/tags.md
+++ b/_tabs/tags.md
@@ -1,31 +1,6 @@
---
+layout: tags
title: Tags
icon: fas fa-tags
order: 2
-
-# All the Tags of posts.
-# v2.0
-# https://github.com/cotes2020/jekyll-theme-chirpy
-# © 2017-2019 Cotes Chung
-# MIT License
---
-
-{% comment %}
- 'site.tags' looks like a Map, e.g. site.tags.MyTag.[ Post0, Post1, ... ]
- Print the {{ site.tags }} will help you to understand it.
-{% endcomment %}
-