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