Jekyll is a static site generator, you cannot make any dynamic site request, but with a litlle imagination, you can do your own clever trick.
“I have searched in google, and I can’t find any relevan link to create ‘Related Posts’ automatically in Jekyll. ‘Related Posts’ is a standard feature in any CMS. I can do this manually by typing in post documents, but it is error prone.”
CMS require a database access to create ‘Related Posts’ feature. It needs table consist of [id, title, url]. Id reference is a must have requirement in relational database, one post to many related-links.
Table, can be simulated by simple array.
Data in Jekyll can be stored in
_datafolder in yml/json/csv format.
Unique ID, can be generated from post date. Or you can use other method that you like.
.:. Thus, ‘read only database access’ can be simulated using simple YAML file.
Step by step
Create a yaml generator using liquid template. It is easier using generator, than type each post’s property manually.
This file will be generated automatically. Copy file above manually to _data/all_posts.yml
What ? Manual ? Yes. It is basically a hack. Breaking the limit of Jekyll just for fun.
You can see the result here. Especialy the unique ID. I’m using date as using id, because it is very common to have date variable in each post, beside title. Date/Time, Title, and URL is standard. No need to create new variable name.
People may change the title anytime, change the URL if necessary, but rarely change the creation date/time. Title is not Unique, but URL is unique. Although date/time is not unique,it is rare to have a post with a very smae date/time. That’s why date can be used as a unique ID.
Put your ‘Related-Posts’ in your posts
Using frontmatter in yml format.
I know this looks primitive, but this is exactly what CMS do without their fancy GUI.
Transformed into page template
Again, using Liquid.
Sample page in action:
I put my ‘Related-Posts’ in my sidebar layout as shown in this figure.
Now your Jekyll behave better than what you can find in stackoverflow.
Smile :-) and Happy Jekyll Brother !
- December 2016
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- June 2016
- May 2016
- April 2016
- March 2016
- February 2016