diff --git a/lib/gollum/helpers.rb b/lib/gollum/helpers.rb index 08bb3fa4..24b8f6db 100644 --- a/lib/gollum/helpers.rb +++ b/lib/gollum/helpers.rb @@ -19,7 +19,7 @@ module Precious # Remove all double slashes def clean_url(url) return url if url.nil? - url.gsub('%2F', '/').gsub(/^\/+/, '').gsub('//', '/') + url.gsub('%2F', '/').gsub(%r{/{2,}}, '/').gsub(%r{^/}, '') end def forbid(msg = "Forbidden. This wiki is set to no-edit mode.") diff --git a/lib/gollum/templates/layout.mustache b/lib/gollum/templates/layout.mustache index d6ea9bbe..d92faeb2 100644 --- a/lib/gollum/templates/layout.mustache +++ b/lib/gollum/templates/layout.mustache @@ -8,7 +8,7 @@ {{#sprockets_stylesheet_tag}}app{{/sprockets_stylesheet_tag}} {{#sprockets_stylesheet_tag}}print print{{/sprockets_stylesheet_tag}} - {{#css}}{{/css}} + {{#css}}{{/css}} {{#noindex}}{{/noindex}} @@ -49,11 +49,11 @@ }; {{#mathjax_config}} - + {{/mathjax_config}} - + {{/mathjax}} - {{#js}}{{/js}} + {{#js}}{{/js}} {{title}} diff --git a/lib/gollum/templates/navbar.mustache b/lib/gollum/templates/navbar.mustache index 3f246a8e..4b71a4bf 100644 --- a/lib/gollum/templates/navbar.mustache +++ b/lib/gollum/templates/navbar.mustache @@ -2,7 +2,7 @@
- Home + Home
diff --git a/lib/gollum/templates/search.mustache b/lib/gollum/templates/search.mustache index b2c30b05..1b04a528 100644 --- a/lib/gollum/templates/search.mustache +++ b/lib/gollum/templates/search.mustache @@ -13,9 +13,8 @@
{{#results}}
  • - {{filename_count}} - {{count}}  - - {{name}} + {{filename_count}} - {{count}}  + {{name}}
  • diff --git a/lib/gollum/views/has_page.rb b/lib/gollum/views/has_page.rb index 2f781357..b4a3e50c 100644 --- a/lib/gollum/views/has_page.rb +++ b/lib/gollum/views/has_page.rb @@ -15,9 +15,5 @@ module Precious def id @page.sha end - - def full_url_path - ::File.join(@base_url, escaped_url_path) - end end end diff --git a/lib/gollum/views/helpers.rb b/lib/gollum/views/helpers.rb index ba02aa5f..a1b2dc0d 100644 --- a/lib/gollum/views/helpers.rb +++ b/lib/gollum/views/helpers.rb @@ -39,7 +39,7 @@ module Precious route_path = "#{prefix}/#{path}" @@route_methods[name.to_s] = route_path define_method :"#{name.to_s}_path" do - "#{base_url}/#{route_path}".gsub(/\/{2,}/, '/') # remove double slashes + page_route(route_path) end end end @@ -53,8 +53,15 @@ module Precious end end - def page_route(page) - "#{base_url}/#{page}".gsub(/\/{2,}/, '/') # remove double slashes + def page_route(page = nil) + clean_url(@base_url, page) + end + + def clean_url(*url) + url.compact! + return nil if url.empty? + + ::File.join(*url).gsub(%r{/{2,}}, '/') end end diff --git a/lib/gollum/views/layout.rb b/lib/gollum/views/layout.rb index 718c9172..bfe3decc 100644 --- a/lib/gollum/views/layout.rb +++ b/lib/gollum/views/layout.rb @@ -31,7 +31,23 @@ module Precious end def custom_path - "#{@base_url}" + @base_url + end + + def custom_css + clean_url(custom_path, "custom.css") + end + + def custom_js + clean_url(custom_path, "custom.js") + end + + def mathjax_config + page_route(@mathjax_config) + end + + def mathjax_js + page_route("gollum/assets/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML") end def css # custom css diff --git a/lib/gollum/views/overview.rb b/lib/gollum/views/overview.rb index 9eb3a715..67a66c60 100644 --- a/lib/gollum/views/overview.rb +++ b/lib/gollum/views/overview.rb @@ -52,7 +52,7 @@ module Precious folder_url = "#{overview_path}/#{folder_path}/" files_and_folders << {name: folder_name, icon: rocticon('file-directory'), type: 'dir', url: folder_url, is_file: false} elsif result_path != '.gitkeep' - file_url = "#{@base_url}/#{result.escaped_url_path}" + file_url = page_route(result.escaped_url_path) files_and_folders << {name: result.filename, icon: rocticon('file'), type: 'file', url: file_url, is_file: true} end end diff --git a/lib/gollum/views/page.rb b/lib/gollum/views/page.rb index 9ffcddea..061397ec 100644 --- a/lib/gollum/views/page.rb +++ b/lib/gollum/views/page.rb @@ -169,6 +169,10 @@ module Precious @navbar end + def full_url_path + page_route(@page.escaped_url_path) + end + # Access to embedded metadata. # # Returns Hash. diff --git a/lib/gollum/views/search.rb b/lib/gollum/views/search.rb index ca075f70..05da778f 100644 --- a/lib/gollum/views/search.rb +++ b/lib/gollum/views/search.rb @@ -5,7 +5,7 @@ module Precious include Pagination def results - @results.sort do |a, b| + sorted = @results.sort do |a, b| if b.nil? b_filename_count = 0 b_count = 0 @@ -15,6 +15,7 @@ module Precious end [a[:filename_count], a[:count]] <=> [b_filename_count, b_count] end.reverse.slice((@page_num - 1) * @max_count, @max_count) + sorted.each {|x| x[:href] = page_route(x[:name])} end def query_string