How to add exceptions to front-matter defaults in Jekyll?

Viewed 20

I have some front matter defaults in my _config.yaml file:

defaults:
  - scope:
      path: "./Articles"
    values:
      parent: Articles
      nav_exclude: true
  - scope:
      path: "./Books"
    values:
      parent: Books
      nav_exclude: true

Basically, it takes every file in the directory ./Articles and ./Books and makes it a child of the index files in the directory (github repo: https://github.com/Fr06t/reading-notes/). The problem is, it also makes the index files childs of themselves. Is there a way to exempt them?

1 Answers

The front matter defaults fill in the gaps for your front matter from your files targeted. If you want the index files to have a different value, the easiest way would be to add parent: null to those files.

e.g. ./Books/index.md:

---
parent: null
nav_exclude: false
# Existing front matter here as well
---

This null value would be prioritised over the defaults in your _config.yml. Alternatively, you could add another defaults entry for those files, you'd just want to check it's taking priority:

defaults:
  - scope:
      path: "./Articles/index.md"
    values:
      parent: null
      nav_exclude: false
Related