diff --git a/lib/gollum/frontend/views/page.rb b/lib/gollum/frontend/views/page.rb index 9d98263f..4b4b738d 100644 --- a/lib/gollum/frontend/views/page.rb +++ b/lib/gollum/frontend/views/page.rb @@ -8,7 +8,7 @@ module Precious DEFAULT_AUTHOR = 'you' def title - @page.url_path.gsub("-", " ") + @page.url_path_title end def page_header diff --git a/lib/gollum/page.rb b/lib/gollum/page.rb index f056659f..9a295158 100644 --- a/lib/gollum/page.rb +++ b/lib/gollum/page.rb @@ -168,6 +168,27 @@ module Gollum path end + # Public: Defines title for page.rb + # + # Returns the String title + def url_path_title + metadata_title || url_path.gsub("-", " ") + end + + # Public: Metadata title + # + # Set with in page content + # + # Returns the String title or nil if not defined + def metadata_title + if metadata + title = metadata['title'] + return title unless title.nil? + end + + nil + end + # Public: The url_path, but CGI escaped. # # Returns the String url_path diff --git a/test/test_wiki.rb b/test/test_wiki.rb index d5b2209c..0cbeb822 100644 --- a/test/test_wiki.rb +++ b/test/test_wiki.rb @@ -198,6 +198,14 @@ context "Wiki page writing" do assert_equal cd[:email], @wiki.repo.commits.first.author.email end + test "page title override with metadata" do + @wiki.write_page("Gollum", :markdown, "", commit_details) + + page = @wiki.page("Gollum") + + assert_equal 'Over', page.url_path_title + end + test "update page with format change" do @wiki.write_page("Gollum", :markdown, "# Gollum", commit_details)