Skip to content

Commit

Permalink
Set missing title from slug early on so it is used in <title>s.
Browse files Browse the repository at this point in the history
  • Loading branch information
henrik committed Apr 13, 2009
1 parent ab5f86e commit 663dfa0
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/jekyll/post.rb
Expand Up @@ -45,7 +45,7 @@ def initialize(site, source, dir, name)
self.data = self.site.post_defaults.dup
self.read_yaml(@base, name)

extract_title_from_first_header
extract_title_from_first_header_or_slug

if self.data.has_key?('published') && self.data['published'] == false
self.published = false
Expand Down Expand Up @@ -136,10 +136,7 @@ def id
#
# Returns <String>
def title
@title ||= begin
(self.data && self.data["title"]) ||
self.slug.split('-').select {|w| w.capitalize! || w }.join(' ')
end
self.data && self.data["title"]
end

# The post date and time
Expand Down Expand Up @@ -214,10 +211,10 @@ def write(dest)
end
end

# Attempt to extract title from topmost header.
# Attempt to extract title from topmost header or slug.
#
# Returns <String>
def extract_title_from_first_header
def extract_title_from_first_header_or_slug
# Done before the transformation to HTML, or it won't go into <title>s.
self.data["title"] ||=
case content_type
Expand All @@ -227,6 +224,7 @@ def extract_title_from_first_header
self.content[/\A\s*#+\s*(.+)\s*#*$/, 1] || # "# Header"
self.content[/\A\s*(\S.*)\r?\n\s*(-+|=+)\s*$/, 1] # "Header\n====="
end
self.data["title"] ||= self.slug.split('-').select {|w| w.capitalize! || w }.join(' ')
end

# Convert this post into a Hash for use in Liquid templates.
Expand Down

0 comments on commit 663dfa0

Please sign in to comment.