Full URL navigation support

This commit is contained in:
maddiebaka
2023-08-07 21:02:09 -04:00
parent a9f340153c
commit 22cf104f6e
6 changed files with 31 additions and 13 deletions

View File

@@ -24,15 +24,25 @@ module Skeksis
class GemBridge
def initialize
@gemini_uri = YAML.load(File.read("config.yml"))['skeksis_config']['gemini_uri']
config = YAML.load(File.read("config.yml"))
@gemini_uri = config['skeksis_config']['gemini_uri']
@serve_dir = config['skeksis_config']['serve_dir']
end
def query(path, env)
if Dir.exist?(path)
#return Dir.each_child(path).map {|i| "#{i}\n"}
return create_dir_listing(path, env)
elsif File.exist?(path)
file = File.open(path, 'r')
# Chomps the first / and builds path
full_path = Pathname.new(@serve_dir) + path[1..-1]
puts full_path.to_s
if Dir.exist?(full_path)
index_file = full_path + "index.gmi"
if File.exist?(index_file)
data = File.open(index_file, 'r').readlines
[htmlize(data, env)]
else
create_dir_listing(full_path, env)
end
elsif File.exist?(full_path)
file = File.open(full_path, 'r')
data = file.readlines
[htmlize(data, env)]
else # path is invalid

View File

@@ -60,13 +60,21 @@ module Skeksis
html
end
# TODO: Relative and absolute links need to be properly handled, both proxied and non
def build_uri(link)
uri = URI.parse(link)
if uri.relative? then puts "relative" else puts "absolute" end
if uri.relative?
path = Pathname.new(@http.path).join(uri.path)
return URI::HTTP.build(host: @http.host, path: path.to_s, port: @http.port)
end
if uri.host == @proxied_uri.host
URI::HTTP.build(host: @http.host, path: uri.path, port: @http.port)
return URI::HTTP.build(host: @http.host, path: uri.path, port: @http.port)
else
link
return link
end
end
end