Skip to content

Instantly share code, notes, and snippets.

@nlowe
Created May 18, 2015 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nlowe/9719820d157a24b37afd to your computer and use it in GitHub Desktop.
Save nlowe/9719820d157a24b37afd to your computer and use it in GitHub Desktop.
Potential fix for gollum/gollum#1012
#...
def files_folders
if has_results
folders = {}
page_files = {}
# 1012: Folders and Pages need to be separated
@results.each do |page|
page_path = page.path.sub(/^#{@path}\//, '')
if page_path.include?('/')
folder = page_path.split('/').first
folder_path = @path ? "#{@path}/#{folder}" : folder
folder_link = %{<li><a href="#{@base_url}/pages/#{folder_path}/" class="folder">#{folder}</a></li>}
folders[folder] = folder_link unless folders.key?(folder_link)
elsif page_path != ".gitkeep"
if defined? page.format
page_link = %{<li><a href="#{@base_url}/#{page.escaped_url_path}" class="file">#{page.name}</a></li>}
page_files[page.name] = page_link
else
page_link = %{<li><a href="#{@base_url}/#{page.escaped_url_path}#{page.name}" class="file">#{page.name}</a></li>}
page_files[page.name] = page_link
end
end
end
# 1012: All Pages should be rendered as Folders first, then Pages, each sorted alphabetically
result = folders.sort_by{ |k, v| k.downcase }.compact.map{ |f| f[1] }.join("\n")
result += page_files.sort_by{ |k, v| k.downcase }.compact.map{ |p| p[1] }.join("\n")
result
else
""
end
end
#...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment