mirror of
https://github.com/neocities/neocities.git
synced 2025-08-02 07:41:52 +02:00
fix up file uris/uri path code
This commit is contained in:
parent
1794a4bcba
commit
dee9128cb3
4 changed files with 23 additions and 13 deletions
|
@ -1244,8 +1244,10 @@ class Site < Sequel::Model
|
|||
def file_list(path='')
|
||||
list = Dir.glob(File.join(files_path(path), '*'), File::FNM_DOTMATCH).reject { |entry| File.basename(entry) == '.' || File.basename(entry) == '..' }.collect do |file_path|
|
||||
extname = File.extname file_path
|
||||
path = file_path.gsub(base_files_path+'/', '')
|
||||
file = {
|
||||
path: file_path.gsub(base_files_path+'/', ''),
|
||||
path: path,
|
||||
uri: uri(path),
|
||||
name: File.basename(file_path),
|
||||
ext: extname.gsub('.', ''),
|
||||
is_directory: File.directory?(file_path),
|
||||
|
@ -1426,13 +1428,20 @@ class Site < Sequel::Model
|
|||
'https'
|
||||
end
|
||||
|
||||
def uri
|
||||
"#{default_schema}://#{host}"
|
||||
end
|
||||
def uri(path=nil)
|
||||
uri = "#{default_schema}://#{host}"
|
||||
|
||||
def file_uri(path)
|
||||
path = '/' + path unless path[0] == '/'
|
||||
uri + (path =~ ROOT_INDEX_HTML_REGEX ? '/' : path)
|
||||
return uri unless path
|
||||
|
||||
path = '' if path == '/' || path =~ ROOT_INDEX_HTML_REGEX
|
||||
path = path.sub(%r{^/}, '').sub(%r{/index\.html$}, '/').sub(/\.html$/, '')
|
||||
|
||||
unless path.empty?
|
||||
escaped_path = Rack::Utils.escape_path(path).gsub('?', '%3F')
|
||||
uri += "/#{escaped_path}"
|
||||
end
|
||||
|
||||
uri
|
||||
end
|
||||
|
||||
def title
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue