Implement Page#title.
This commit is contained in:
@@ -223,9 +223,7 @@ html {overflow-y: scroll;}
|
||||
}
|
||||
|
||||
.wikistyle h1:first-child {
|
||||
margin-top: 0 !important;
|
||||
padding-top: .25em !important;
|
||||
border-top: none !important;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.wikistyle h2 {
|
||||
|
||||
@@ -4,7 +4,7 @@ module Precious
|
||||
attr_reader :content, :page
|
||||
|
||||
def human_name
|
||||
@name.gsub(/-/, ' ')
|
||||
@page.title
|
||||
end
|
||||
|
||||
def title
|
||||
|
||||
+23
-1
@@ -52,6 +52,28 @@ module Gollum
|
||||
@blob && @blob.name
|
||||
end
|
||||
|
||||
# Public: If the first element of a formatted page is an <h1> tag it can
|
||||
# be considered the title of the page and used in the display. If the
|
||||
# first element is NOT an <h1> tag, the title will be constructed from the
|
||||
# filename by stripping the extension and replacing any dashes with
|
||||
# spaces.
|
||||
#
|
||||
# Returns the fully sanitized String title.
|
||||
def title
|
||||
doc = Nokogiri::HTML(self.formatted_data)
|
||||
if doc.first_element_child &&
|
||||
doc.first_element_child.children &&
|
||||
doc.first_element_child.children.first &&
|
||||
doc.first_element_child.children.first.children &&
|
||||
doc.first_element_child.children.first.children.first &&
|
||||
doc.first_element_child.children.first.children.first.name &&
|
||||
doc.first_element_child.children.first.children.first.name == 'h1'
|
||||
Sanitize.clean(doc.first_element_child.children.first.children.first.to_html)
|
||||
else
|
||||
Sanitize.clean(self.name.split('.')[0..-2].join('.').gsub('-', ' '))
|
||||
end
|
||||
end
|
||||
|
||||
# Public: The path of the page within the repo.
|
||||
#
|
||||
# Returns the String path.
|
||||
@@ -134,7 +156,7 @@ module Gollum
|
||||
#
|
||||
# Returns the String canonical name.
|
||||
def self.cname(name)
|
||||
name.gsub(%r{[ /]}, '-')
|
||||
name.gsub(%r{[ /<>]}, '-')
|
||||
end
|
||||
|
||||
# Convert a format Symbol into an extension String.
|
||||
|
||||
Reference in New Issue
Block a user