Creating this Blog using Jekyll

So, my initial plan to create this blog was to build it from scratch, brick by brick, maybe even make a content management system on the way. However, due to a lack of time and a general decision in life to stop rebuilding the wheel every single time, I decided to use something someone wise has already built.

I did intially go for a framework called CMSjs which I found here but for some reason I did not like the way it worked. Finally I settled down to Jekyll and decided to get version 1 of the blog up and running as soon as possible instead of trying to find the perfect tool out there. Barry Clark, a Web Developer from NY, has this very straight-forward article to set up a minimal blog by forking a starting-point that he has created. Following it was a breeze, and before I knew it I had a pretty decent looking blog in my hands.

Subpage with different posts

Once I had the basic blog ready, I decided to post about 24 summaries that I had made about ML Based Malware Detection Systems over the past 6 months. However, I did not want to make my homepage messy by having all these summaries in there. What I wanted was a brief post in the homepage “sid-38.github.io” that will lead you to a sub-page “sid-38.github.io/mlcyber” which would contain all the summaries. Alright, so how to create pages in Jekyll?

You can just create a Markdown file with the layout as “page” and that would work pretty well. However, I did not want to create one HUGE markdown file that contains 24 articles inside it. That would be a really long file, won’t it? What I wanted was for my MLCyber page to fetch all the posts and display it just like my homepage does.

How Jekyll works normally is, it’ll fetch the files from the _posts directory when you use the variable “site.posts”. This allows you to iterate through it and display it in your html page. So I figured if I create a subdirectory called “MLCyber”, create an html file “MLCyber.html” inside of it along with a subdirectory _posts, maybe it could work.

Root
  _posts
  MLCyber
     mlcyber.html
     _posts
        post1.md
        post2.md

Maybe, if I use “site.posts” inside of mlcyber.html it’ll only see post1 and post2? Well, that did not work but I was pretty close. After a number of iterations and even going into Jekyll Collections, none of it worked.

How to get posts from subdirectories

Jekyll has a concept of categories. Utilizing categories, it is possible to maintain the structure shown above and get the render we were looking for. For the mlcyber posts, in the frontmatter of jekyll, add “category: mlcyber”. And to iterate over just the posts in the category mlcyber, inside mlcyber.html do the following.

{% for post in site.categories.mlcyber %}  

I saw a number of articles that said if the posts are inside a subdirectory it should by default be assigned a category based on the parent directory name. This would have been extremely convenient, but it did not work for me when I tried it out. I also tried putting the subdirectory mlcyber which contained post1.md and post2.md, inside the root _posts. Even that combination did not assign the category automatically. Well, maybe I made some typo somewhere or something, I don’t know.

Alright, that’s step 1 done. Now to fix the next issue. The homepage now shows every post, including the mlcyber posts. How do I display just the posts that did not have a category assigned to them?

{% if post.categories.size == 0 %}

Yup, that pretty much got the blog to where I wanted it to be. Now, onwards and upwards to more posts.

Written on May 1, 2023