Unit 06 · lesson
Front Matter Defaults
If every project repeats the same front-matter value, that value may not belong in every project.
Jekyll supports front-matter defaults in _config.yml.
Repetition first
Suppose every project contains:
layout: project
and every post contains:
layout: post
That is predictable configuration disguised as content.
Set a default
A pattern adapted from Jekyll's collections tutorial:
defaults:
- scope:
path: ""
type: "projects"
values:
layout: project
- scope:
path: ""
type: "posts"
values:
layout: post
Now individual documents can omit the repeated layout field.
Scope is the important part
A default is only safe if its scope is correct.
If you accidentally apply layout: project to every page, the build may succeed while unrelated content gets the wrong template.
Override behavior
Test one project with an explicit layout value that differs from the default.
Record which value wins in your Jekyll version and why that override is useful.
Refactor test
- Build before defaults.
- Save generated output.
- Add defaults.
- Remove repeated front-matter keys.
- Restart server/build.
- Compare output.
The source should become less repetitive without changing intended behavior.
Checkpoint
Explain why a default is a form of centralized policy, not just typing convenience.