Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jekyll - How to set YAML front matter default for home page only?

I am currently developing a personal blog using Jekyll (using this blog post for an easy setup guide). I am trying to re-use an HTML file so that one url "/" displays some text while a different url "/posts" displays something slightly different. To do this, I am trying to set a Font Matter Default in _config.yml that will only apply to one of the paths, the home path "/".

Here's the code I'm using to set up the Font Matter Default:

# site defaults (https://jekyllrb.com/docs/configuration/)
defaults:
  - scope:
      path: ""
    values:
      display_num_posts: 5

The issue I'm facing is that path: "" applies to all pages, so my variable display_num_posts will be set to 5 on every page where my HTML file is used (both "/" and "/posts").

My question: How can I set a path to only include the home page? With no extra "/posts" in the url?

I've tried searching on the https://jekyllrb.com/docs/ page, but couldn't find an answer. I also tried setting path: "/", but that path didn't match any url at all.

like image 432
Blundering Philosopher Avatar asked Oct 28 '25 07:10

Blundering Philosopher


1 Answers

Apparently this can be done by setting the path to the base index.html file like this:

# site defaults (https://jekyllrb.com/docs/configuration/)
defaults:
  - scope:
      path: "index.html"
    values:
      display_num_posts: 5

I found this was possible on this blog post.

Hope this helps someone as it helped me.

like image 58
Blundering Philosopher Avatar answered Oct 31 '25 13:10

Blundering Philosopher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!