Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Set missing title from slug early on so it is used in <title>s.

  • Loading branch information...
commit 663dfa00ca6a102301b77520ab49453eefccc7ca 1 parent ab5f86e
@henrik henrik authored
Showing with 5 additions and 7 deletions.
  1. +5 −7 lib/jekyll/post.rb
View
12 lib/jekyll/post.rb
@@ -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
@@ -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
@@ -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
@@ -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.
Please sign in to comment.
Something went wrong with that request. Please try again.