Skip to content

Commit

Permalink
Properly handle pages that exist in sub-dirs in search results
Browse files Browse the repository at this point in the history
  • Loading branch information
MrJoy authored and henrikh committed Aug 31, 2010
1 parent 50c207a commit e923905
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion lib/gollum/page.rb
Expand Up @@ -35,6 +35,14 @@ def self.valid_page_name?(filename)
filename =~ /^_/ ? false : match
end

# Reusable filter to turn a filename (without path) into a canonical name.
# Strips extension, converts spaces to dashes.
#
# Returns the filtered String.
def self.canonicalize_filename(filename)
filename.split('.')[0..-2].join('.').gsub('-', ' ')
end

# Public: Initialize a page.
#
# wiki - The Gollum::Wiki in question.
Expand All @@ -57,7 +65,7 @@ def filename
#
# Returns the String name.
def name
filename.split('.')[0..-2].join('.').gsub('-', ' ')
self.class.canonicalize_filename(filename)
end

# Public: If the first element of a formatted page is an <h1> tag it can
Expand Down
4 changes: 2 additions & 2 deletions lib/gollum/wiki.rb
Expand Up @@ -219,11 +219,11 @@ def search(query)

search_output.split("\n").collect do |line|
result = line.split(':')
file_name = result[1]
file_name = Gollum::Page.canonicalize_filename(::File.basename(result[1]))

{
:count => result[2].to_i,
:name => file_name.split('.').first
:name => file_name
}
end
end
Expand Down

0 comments on commit e923905

Please sign in to comment.