From e310f760303ea99ff561b3129d0496245f31c6ec Mon Sep 17 00:00:00 2001 From: "Watal M. Iwasaki" Date: Sun, 14 Jun 2020 22:49:26 +0900 Subject: [PATCH 1/8] Enhance RouteHelpers - page_route() accepts nil and return base_url - clean_url() accepts multiple args and join them --- lib/gollum/views/helpers.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/gollum/views/helpers.rb b/lib/gollum/views/helpers.rb index ba02aa5f..a2cc8991 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 url if url.nil? + + ::File.join(*url).gsub(%r{/{2,}}, '/') end end From 214056a88a0e0438acf357e4d164114d623d2e8f Mon Sep 17 00:00:00 2001 From: "Watal M. Iwasaki" Date: Sun, 14 Jun 2020 22:55:16 +0900 Subject: [PATCH 2/8] Refactor regex in clean_url() --- lib/gollum/helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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.") From 504278d9ba67528d601c63c420aa6ba66b13d95d Mon Sep 17 00:00:00 2001 From: "Watal M. Iwasaki" Date: Sun, 14 Jun 2020 22:56:45 +0900 Subject: [PATCH 3/8] Move full_url_path from HasPage to Page so that page_route() is accessible via Layout --- lib/gollum/views/has_page.rb | 4 ---- lib/gollum/views/page.rb | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) 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/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. From 580068212db0a127d216aeee1b3aab0ebb0506c6 Mon Sep 17 00:00:00 2001 From: "Watal M. Iwasaki" Date: Sun, 14 Jun 2020 22:57:37 +0900 Subject: [PATCH 4/8] Remove base_url from search.mustache --- lib/gollum/templates/search.mustache | 5 ++--- lib/gollum/views/search.rb | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) 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/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 From e49758334fc30e18ec5f1444b4563fffb7129949 Mon Sep 17 00:00:00 2001 From: "Watal M. Iwasaki" Date: Sun, 14 Jun 2020 23:01:38 +0900 Subject: [PATCH 5/8] Replace base_url with page_route() --- lib/gollum/templates/layout.mustache | 2 +- lib/gollum/templates/navbar.mustache | 2 +- lib/gollum/views/overview.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/gollum/templates/layout.mustache b/lib/gollum/templates/layout.mustache index d6ea9bbe..6ba4d92d 100644 --- a/lib/gollum/templates/layout.mustache +++ b/lib/gollum/templates/layout.mustache @@ -14,7 +14,7 @@ {{#mathjax_config}} - + {{/mathjax_config}} - + {{/mathjax}} - {{#js}}{{/js}} + {{#js}}{{/js}} {{title}} diff --git a/lib/gollum/views/layout.rb b/lib/gollum/views/layout.rb index 718c9172..22855a43 100644 --- a/lib/gollum/views/layout.rb +++ b/lib/gollum/views/layout.rb @@ -26,12 +26,24 @@ module Precious !@path.nil? end - def base_url + def custom_path @base_url end - def custom_path - "#{@base_url}" + 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 From 6c7b12ae5ef95a3515885e9a268d049954eca893 Mon Sep 17 00:00:00 2001 From: "Watal M. Iwasaki" Date: Tue, 16 Jun 2020 17:29:32 +0900 Subject: [PATCH 7/8] Restore base_url for baseUrl in JavaScript --- lib/gollum/templates/layout.mustache | 2 +- lib/gollum/views/layout.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/gollum/templates/layout.mustache b/lib/gollum/templates/layout.mustache index 6290eeb1..d92faeb2 100644 --- a/lib/gollum/templates/layout.mustache +++ b/lib/gollum/templates/layout.mustache @@ -14,7 +14,7 @@