Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Support post_defaults section in _config.yml, typically used to set a…
Browse files Browse the repository at this point in the history
… default layout for posts.

Based on code by geekq: http://github.com/geekq/jekyll/commit/2d4274ecbc97a0810a51a55f04aa9d9b53561de8
  • Loading branch information
henrik committed Apr 12, 2009
1 parent 56e1707 commit 77bf31c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
12 changes: 12 additions & 0 deletions README.textile
Expand Up @@ -238,6 +238,15 @@ Parameters set in a configuration file override the default values. Parameters
set using command line options override both the default values and those set
in a configuration file.

Additionally, you can set defaults for the post data blocks. For example, you
can set the default layout for posts, so you don't have to specify it in every
post:

post_defaults:
layout: post

Any values set in the actual post will override these defaults.

h2. Data

Jekyll traverses your site looking for files to process. Any files with YAML
Expand Down Expand Up @@ -329,6 +338,9 @@ h3. Predefined Global Variables
If set, this specifies the layout file to use. Use the layout file
name without file extension. Layout files must be placed in the
<code>_layouts</code> directory.

A default layout for posts can be set in the configuration file.
See above.

h3. Predefined Post Variables

Expand Down
3 changes: 2 additions & 1 deletion lib/jekyll/convertible.rb
Expand Up @@ -21,7 +21,8 @@ def read_yaml(base, name)
if self.content =~ /^(---\s*\n.*?)\n---\s*\n/m
self.content = self.content[($1.size + 5)..-1]

self.data = YAML.load($1)
self.data ||= {}
self.data = self.data.merge(YAML.load($1))
end
end

Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/post.rb
Expand Up @@ -42,6 +42,7 @@ def initialize(site, source, dir, name)
self.topics = parts.size > 1 ? parts[0..-2] : []

self.process(name)
self.data = self.site.post_defaults.dup
self.read_yaml(@base, name)

if self.data.has_key?('published') && self.data['published'] == false
Expand Down
4 changes: 3 additions & 1 deletion lib/jekyll/site.rb
Expand Up @@ -2,7 +2,8 @@ module Jekyll

class Site
attr_accessor :config, :layouts, :posts, :categories
attr_accessor :source, :dest, :lsi, :pygments, :permalink_style, :permalink_date, :sass
attr_accessor :source, :dest, :lsi, :pygments, :permalink_style, :permalink_date,
:sass, :post_defaults

# Initialize the site
# +config+ is a Hash containing site configurations details
Expand All @@ -17,6 +18,7 @@ def initialize(config)
self.pygments = config['pygments']
self.permalink_style = config['permalink'].to_sym
self.permalink_date = config['permalink_date'] && config['permalink_date'].sub(%r{\A/?(.*)/?\Z}, '/\1/')
self.post_defaults = config['post_defaults'] || {}

self.reset
self.setup
Expand Down

0 comments on commit 77bf31c

Please sign in to comment.