2
votes

What is the proper approach for generating a Jekyll site but excluding certain content based on Frontmatter.

For example, I have a any number of pages that have front-matter of "access: confidential" ... I want to build my jekyll site and have it not include any of that content in the _site build out.

2

2 Answers

1
votes

All Jekyll files are copied to destination, except if they are :

This exclusion cannot rely on a front matter variable (you can do this with a plugin, but it's not the subject here).

Now, you can exclude all your confidential pages like this in _config.yml :

# exclude all files in confidential folder from being processed
exclude:
 - confidential/ 
0
votes

In addition to the options on David's answer, you could set published to false in your front matter for the files you want excluded.

From https://jekyllrb.com/docs/frontmatter/:

published

Set to false if you don’t want a specific post to show up when the site is generated.

Although the official documentation only mentions posts, I've just tested it works for posts, pages and collection items on Jekyll 3.2.1:

---
published: false
---