From a5e19e38419b5eba2ad61c4f73d82e8133ac732d Mon Sep 17 00:00:00 2001 From: restitux Date: Tue, 17 Jan 2023 20:34:51 -0700 Subject: [PATCH] Change path lookup to support abrev paths --- lib/gollum/app.rb | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb index 0c81385d..36237568 100644 --- a/lib/gollum/app.rb +++ b/lib/gollum/app.rb @@ -560,6 +560,7 @@ module Precious wiki = wiki_new @results = wiki.tree_list + if path @path = Pathname.new(path).cleanpath.to_s check_path = wiki.page_file_dir ? ::File.join(wiki.page_file_dir, @path, '/') : "#{@path}/" @@ -624,26 +625,42 @@ module Precious end end - def show_page_or_file(fullpath) - wiki = wiki_new - if page = wiki.page(fullpath) - @page = page - @name = page.filename_stripped - @content = page.formatted_data - @upload_dest = find_upload_dest(Pathname.new(fullpath).cleanpath.to_s) + def folder_exists(path, wiki) + paths = wiki.tree_list + return paths.any? { |item| item.path.start_with?(path) } + end - # Extensions and layout data - @editable = true - @toc_content = wiki.universal_toc ? @page.toc_data : nil - @h1_title = wiki.h1_title - @bar_side = wiki.bar_side - @allow_uploads = wiki.allow_uploads - @navbar = true - mustache :page + def show_page(page, fullpath, wiki) + @page = page + @name = page.filename_stripped + @content = page.formatted_data + @upload_dest = find_upload_dest(Pathname.new(fullpath).cleanpath.to_s) + + # Extensions and layout data + @editable = true + @toc_content = wiki.universal_toc ? @page.toc_data : nil + @h1_title = wiki.h1_title + @bar_side = wiki.bar_side + @allow_uploads = wiki.allow_uploads + @navbar = true + return mustache :page + end + + def show_page_or_file(fullpath) + wiki = wiki_new + + if fullpath[-1] != '/' ? page = wiki.page(fullpath) : false + show_page(page, fullpath, wiki) + elsif page = wiki.page("#{fullpath}/#{wiki.index_page}") + show_page(page, fullpath, wiki) + elsif page = wiki.page("#{fullpath}/#{File.basename(fullpath)}") + show_page(page, fullpath, wiki) elsif file = wiki.file(fullpath, wiki.ref, true) show_file(file) elsif @redirects_enabled && redirect_path = wiki.redirects[fullpath] redirect to("#{encodeURIComponent(redirect_path)}?redirected_from=#{encodeURIComponent(fullpath)}") + elsif folder_exists(fullpath, wiki) + redirect to("/gollum/overview/#{clean_url(encodeURIComponent(fullpath))}") else if @allow_editing && @user_authed path = fullpath[-1] == '/' ? "#{fullpath}#{wiki.index_page}" : fullpath # Append default index page if no page name is supplied