Subcategory for Jekyll Github pages
Now this blog has subcategories. Check math category page and its subcategory math/number-theory category page. The depth of subcategories can be greater than 2.
I don’t like the way I implemented this feature, so I don’t want to explain it in detail. Check the difference to see the changes.
In brief,
- I defined the category structures like
math/number-theory. Thecategorykey of each post can be given likecategory: mathorcategory: math/number-theory, etc. - I added the directories to resemble the category structure and corresponding
.mdfiles in_categories/. For example, the category structure for now isblog math └number-theory miscellaneousand the corresponding
_categories/structure is_categories/ └math/ └number-theory.md └blog.md └math.md └miscellaneous.md(Note that the slash symbol at the end of
(directory_name)/means that it is a directory, not a file.)Each file in
_categories/has new keyparent_categorywhose value is all of its ancestors (from top level to lower level). For example,_categories/math/number-theory.mdfile has--- catname: "math/number-theory" parent_category: ["math"] layout: "category" permalink: "category/math/number-theory" --- - I modified
_layouts/category.html,category.mdfiles.- The
_layouts/category.htmlfile shows the list of post under the category. Now,- it makes the hyperlinks to all of its ancestors category in heading, and
- it shows the list of its descendant categories (if it has any).
- The
category.mdfile shows the list of all categories of the blog. Now,- it shows the list of all categories with tree-like structure with indentation.
- The
Possible issues on this implementation:
- I think there are no
startswith-like command for strings in Jekyll. I usedcontainsinstead; this means that I cannot make subcategory with another category name. For example,math/history-of-mathematicscategory will cause some problems. _layouts/category.htmlfile uses both of the string for category, for examplemath/number-theory, and the list of its ancestors, for example["math"]. This is absurd, and the structure can be simplified.- (2022.1.20.) Now the variable
parent_categoryof category page is not used.
- (2022.1.20.) Now the variable
Minor update on 8th April 2024: Some urls have been updated since the blog url has been changed.