Tweak front-matter vs site configuration per comments from @parkr on jekyll/jekyll#2439

This commit is contained in:
Terry Schmidt 2014-05-27 10:14:28 -05:00
parent a0595a00e8
commit 4dcb877ff9
1 changed files with 14 additions and 25 deletions

View File

@ -278,25 +278,15 @@ before your site is served.
## Frontmatter defaults ## Frontmatter defaults
Using [YAML front-matter](../frontmatter/) is one way that you can specify configuration in your Using [YAML front-matter](../frontmatter/) is one way that you can specify configuration in your pages and posts for your site. Things like setting a default layout, or customizing the title, or specifying a more precise date/time for the post can all be added to your page or post front-matter.
pages and posts for your site. Things like setting a default layout, or customizing the title,
or specifying a more precise date/time for the post can all be added to your page or post
front-matter.
Often times, you will find that you are repeating a lot of configuration options. Setting the Often times, you will find that you are repeating a lot of configuration options. Setting the same layout in each file, adding the same category - or categories - to a post, etc. You can even add custom variables like author names, which might be the same for the majority of posts in your project.
same layout in each file, adding the same category - or categories - to a post, etc. You can even
add custom variables like author names, which might be the same for the majority of posts
in your project.
Instead of repeating this configuration each time you create a new post or page, Jekyll provides Instead of repeating this configuration each time you create a new post or page, Jekyll provides a way to set these defaults in the site configuration. To do this, you can specify site-wide defaults using the `defaults` key in the `_config.yml` file in your projects root directory.
a way to set these defaults in the site front-matter. To do this, you can specify site-wide
defaults using the `defaults` key in the `_config.yml` file in your projects root directory.
The `defaults` key holds an array of scope/values pairs that define what defaults should be set for The `defaults` key holds an array of scope/values pairs that define what defaults should be set for a particular file path, and optionally, a file type in that path.
a particular file path, and optionally, a file type in that path.
Let's say that you want to add a default layout to all pages and posts in your site. You would add Let's say that you want to add a default layout to all pages and posts in your site. You would add this to your `_config.yml` file:
this to your `_config.yml` file:
{% highlight yaml %} {% highlight yaml %}
defaults: defaults:
@ -337,18 +327,17 @@ defaults:
layout: "my-site" layout: "my-site"
- -
scope: scope:
path: "about/blog" path: "projects"
type: "post" type: "page"
values: values:
layout: "meta-blog" # overrides previous default layout layout: "project" # overrides previous default layout
author: "Dr. Hyde" author: "Mr. Hyde"
category: "about" category: "project"
{% endhighlight %} {% endhighlight %}
With these defaults, all posts would use the `my-site` layout except for the posts under With these defaults, all posts would use the `my-site` layout. Any html files that exist in the `projects/` folder will use the `project` layout. Those files will also have the `page.author`
`about/blog`. Those posts would use the `meta-blog` layout and also have the `page.author` [liquid variable](../variables/) set to `Mr. Hyde` as well as have the category for the page
[liquid variable](../variables/) set to `Dr. Hyde` as well as have the category for the post set to `project`.
set to `about`.
### Precedence ### Precedence
@ -360,7 +349,7 @@ You can see that in the last example above. First, we set the default layout to
using a more specific path, we set the default layout for posts in the `about/blog` path to using a more specific path, we set the default layout for posts in the `about/blog` path to
`meta-blog`. This can be done with any value that you would set in the page or post front-matter. `meta-blog`. This can be done with any value that you would set in the page or post front-matter.
Finally, if you set defaults in the site front-matter by adding a `defaults` section to your Finally, if you set defaults in the site configuration by adding a `defaults` section to your
`_config.yml` file, you can override those settings in a post or page file. All you need to do `_config.yml` file, you can override those settings in a post or page file. All you need to do
is specify the settings in the post or page front-matter. For example: is specify the settings in the post or page front-matter. For example: