Skip to content

Commit

Permalink
dealing with missing yaml header: defaults, process markdown h1; reco…
Browse files Browse the repository at this point in the history
…gnize .md.txt as file extension
  • Loading branch information
geekq committed Mar 20, 2009
1 parent 884583c commit 2d4274e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lib/jekyll/convertible.rb
Expand Up @@ -15,8 +15,7 @@ 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.merge YAML.load($1)
end
end

Expand Down
12 changes: 11 additions & 1 deletion lib/jekyll/post.rb
Expand Up @@ -8,7 +8,8 @@ class << self
attr_accessor :lsi
end

MATCHER = /^(.+\/)*(\d+-\d+-\d+)-(.*)(\.[^.]+)$/
MATCHER = /^(.+\/)*(\d+-\d+-\d+)-(.*)((?:\.md)?\.[^.]+)$/
DEFAULT_DATA = {'layout' => 'post'}

# Post name validator. Post filenames must be like:
# 2008-11-05-my-awesome-post.textile
Expand All @@ -22,6 +23,13 @@ def self.valid?(name)
attr_accessor :data, :content, :output
attr_accessor :previous, :next, :numericid, :archivedate

def check_markdown_header
if self.content =~ /(.*)\n===*\n/
self.data['title'] = $1
self.content = self.content[$&.size..-1]
end
end

# Initialize this Post instance.
# +base+ is the String path to the dir containing the post file
# +name+ is the String filename of the post file
Expand All @@ -40,7 +48,9 @@ def initialize(source, dir, name)
self.topics = parts.size > 1 ? parts[0..-2] : []

self.process(name)
self.data = DEFAULT_DATA
self.read_yaml(@base, name)
check_markdown_header

if self.data.has_key?('published') && self.data['published'] == false
self.published = false
Expand Down

1 comment on commit 2d4274e

@henrik
Copy link

@henrik henrik commented on 2d4274e Apr 12, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the DEFAULT_DATA thing more general: http://github.com/henrik/jekyll/commit/a7895e3131eaf020691a7cba8acde8ead17e1948

Please sign in to comment.