Merge pull request #631 from arr2036/master
Fix redirects to index_pages for subdirs
This commit is contained in:
@@ -89,7 +89,7 @@ module Precious
|
|||||||
|
|
||||||
get '/' do
|
get '/' do
|
||||||
page_dir = settings.wiki_options[:page_file_dir].to_s
|
page_dir = settings.wiki_options[:page_file_dir].to_s
|
||||||
redirect clean_url(::File.join(@base_url, page_dir, 'Home'))
|
redirect clean_url(::File.join(@base_url, page_dir, wiki_new.index_page))
|
||||||
end
|
end
|
||||||
|
|
||||||
# path is set to name if path is nil.
|
# path is set to name if path is nil.
|
||||||
@@ -98,13 +98,13 @@ module Precious
|
|||||||
# extract_path will trim path to 'a'
|
# extract_path will trim path to 'a'
|
||||||
# name, path, version
|
# name, path, version
|
||||||
def wiki_page(name, path = nil, version = nil, exact = true)
|
def wiki_page(name, path = nil, version = nil, exact = true)
|
||||||
|
wiki = wiki_new
|
||||||
|
|
||||||
path = name if path.nil?
|
path = name if path.nil?
|
||||||
name = extract_name(name)
|
name = extract_name(name) || wiki.index_page
|
||||||
path = extract_path(path)
|
path = extract_path(path)
|
||||||
path = '/' if exact && path.nil?
|
path = '/' if exact && path.nil?
|
||||||
|
|
||||||
wiki = wiki_new
|
|
||||||
|
|
||||||
OpenStruct.new(:wiki => wiki, :page => wiki.paged(name, path, exact, version),
|
OpenStruct.new(:wiki => wiki, :page => wiki.paged(name, path, exact, version),
|
||||||
:name => name, :path => path)
|
:name => name, :path => path)
|
||||||
end
|
end
|
||||||
@@ -123,6 +123,7 @@ module Precious
|
|||||||
wikip = wiki_page(params[:splat].first)
|
wikip = wiki_page(params[:splat].first)
|
||||||
@name = wikip.name
|
@name = wikip.name
|
||||||
@path = wikip.path
|
@path = wikip.path
|
||||||
|
|
||||||
wiki = wikip.wiki
|
wiki = wikip.wiki
|
||||||
if page = wikip.page
|
if page = wikip.page
|
||||||
if wiki.live_preview && page.format.to_s.include?('markdown') && supported_useragent?(request.user_agent)
|
if wiki.live_preview && page.format.to_s.include?('markdown') && supported_useragent?(request.user_agent)
|
||||||
@@ -379,9 +380,10 @@ module Precious
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show_page_or_file(fullpath)
|
def show_page_or_file(fullpath)
|
||||||
name = extract_name(fullpath)
|
wiki = wiki_new
|
||||||
path = extract_path(fullpath) || '/'
|
|
||||||
wiki = wiki_new
|
name = extract_name(fullpath) || wiki.index_page
|
||||||
|
path = extract_path(fullpath) || '/'
|
||||||
|
|
||||||
if page = wiki.paged(name, path, exact = true)
|
if page = wiki.paged(name, path, exact = true)
|
||||||
@page = page
|
@page = page
|
||||||
|
|||||||
@@ -12,6 +12,12 @@ module Precious
|
|||||||
|
|
||||||
# Extract the 'page' name from the file_path
|
# Extract the 'page' name from the file_path
|
||||||
def extract_name(file_path)
|
def extract_name(file_path)
|
||||||
|
if file_path[-1, 1] == "/"
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
# File.basename is too eager to please and will return the last
|
||||||
|
# component of the path even if it ends with a directory separator.
|
||||||
::File.basename(file_path)
|
::File.basename(file_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+9
-1
@@ -145,6 +145,9 @@ module Gollum
|
|||||||
# Defaults to false
|
# Defaults to false
|
||||||
attr_reader :h1_title
|
attr_reader :h1_title
|
||||||
|
|
||||||
|
# Gets the custom index page for / and subdirs (e.g. foo/)
|
||||||
|
attr_reader :index_page
|
||||||
|
|
||||||
# Public: Initialize a new Gollum Repo.
|
# Public: Initialize a new Gollum Repo.
|
||||||
#
|
#
|
||||||
# path - The String path to the Git repository that holds the Gollum
|
# path - The String path to the Git repository that holds the Gollum
|
||||||
@@ -168,6 +171,11 @@ module Gollum
|
|||||||
# :show_all - Show all files in file view, not just valid pages.
|
# :show_all - Show all files in file view, not just valid pages.
|
||||||
# Default: false
|
# Default: false
|
||||||
# :collapse_tree - Start with collapsed file view. Default: false
|
# :collapse_tree - Start with collapsed file view. Default: false
|
||||||
|
# :css - Include the custom.css file from the repo.
|
||||||
|
# :h1_title - Concatenate all h1's on a page to form the
|
||||||
|
# page title.
|
||||||
|
# :index_page - The default page to retrieve or create if the
|
||||||
|
# a directory is accessed.
|
||||||
#
|
#
|
||||||
# Returns a fresh Gollum::Repo.
|
# Returns a fresh Gollum::Repo.
|
||||||
def initialize(path, options = {})
|
def initialize(path, options = {})
|
||||||
@@ -203,7 +211,7 @@ module Gollum
|
|||||||
@collapse_tree = options.fetch :collapse_tree, false
|
@collapse_tree = options.fetch :collapse_tree, false
|
||||||
@css = options.fetch :css, false
|
@css = options.fetch :css, false
|
||||||
@h1_title = options.fetch :h1_title, false
|
@h1_title = options.fetch :h1_title, false
|
||||||
|
@index_page = options.fetch :index_page, 'Home'
|
||||||
@user_icons = ['gravatar', 'identicon'].include?( options[:user_icons] ) ?
|
@user_icons = ['gravatar', 'identicon'].include?( options[:user_icons] ) ?
|
||||||
options[:user_icons] : 'none'
|
options[:user_icons] : 'none'
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -252,6 +252,24 @@ context "Frontend" do
|
|||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "accessing non-existant directory redirects to create index page" do
|
||||||
|
get "/foo/"
|
||||||
|
|
||||||
|
follow_redirect!
|
||||||
|
assert_equal "/create/foo/Home", last_request.fullpath
|
||||||
|
assert last_response.ok?
|
||||||
|
end
|
||||||
|
|
||||||
|
test "accessing redirectory redirects to index page" do
|
||||||
|
post "/create", :content => 'abc', :page => 'Home', :path => '/foo/',
|
||||||
|
:format => 'markdown', :message => 'foo'
|
||||||
|
|
||||||
|
assert_equal "http://example.org/foo/home", last_response.headers['Location']
|
||||||
|
|
||||||
|
follow_redirect!
|
||||||
|
assert last_response.ok?
|
||||||
|
end
|
||||||
|
|
||||||
test "edit redirects to create on non-existant page" do
|
test "edit redirects to create on non-existant page" do
|
||||||
name = "E"
|
name = "E"
|
||||||
get "/edit/#{name}"
|
get "/edit/#{name}"
|
||||||
|
|||||||
Reference in New Issue
Block a user