Permalink
Browse files

Support post_defaults section in _config.yml, typically used to set a…

… 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 77bf31c42c25c2f87c215348a816b730104fe820
Showing with 18 additions and 2 deletions.
  1. +12 −0 README.textile
  2. +2 −1 lib/jekyll/convertible.rb
  3. +1 −0 lib/jekyll/post.rb
  4. +3 −1 lib/jekyll/site.rb
@@ -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
@@ -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

@@ -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

@@ -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
@@ -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
@@ -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

0 comments on commit 77bf31c

Please sign in to comment.