In order to keep some of my Jekyll sites simple, I'm always using the same layout. That is to say, I'm always writing something like. . .
--- layout: default title: Here's my Title ---
. . . as the YAML Front Matter at the top of my pages.
What I'd rather write, however is only. . .
--- title: Here's my Title ---
. . . and have Jekyll assume that it should use a certain layout, as if I had explicitly written "layout: default
" (or whatever), as above.
I don't see a way to specify this behavior in _config.yml
. Maybe I could write a Jekyll plugin that would allow this. . . any ideas?
Jekyll has an extensive theme system that allows you to leverage community-maintained templates and styles to customize your site's presentation. Jekyll themes specify plugins and package up assets, layouts, includes, and stylesheets in a way that can be overridden by your site's content.
Front matter tells Jekyll to parse a file. You add predefined variables, which are YAML sets, to the front matter. Then, you can use Liquid tags in your files to access the front matter. Front matter is indicated with two triple-dashed lines.
This can be done using Frontmatter defaults:
defaults: - scope: path: "" # empty string for all files values: layout: "default"
This setting is available since Jekyll Version 2.0.0.
Shorter and with no monkey-patching:
# _plugins/implicit_layout.rb module ImplicitLayout def read_yaml(*args) super self.data['layout'] ||= 'post' end end Jekyll::Post.send(:include, ImplicitLayout)
Caveat: GH Pages won't run your plugins.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With