Full URL navigation support
This commit is contained in:
parent
a9f340153c
commit
22cf104f6e
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,3 +10,4 @@
|
|||||||
# rspec failure tracking
|
# rspec failure tracking
|
||||||
.rspec_status
|
.rspec_status
|
||||||
pub_gemini
|
pub_gemini
|
||||||
|
config.yml
|
||||||
|
3
config.example.yml
Normal file
3
config.example.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
skeksis_config:
|
||||||
|
gemini_uri: "gemini://gemini.example.com/"
|
||||||
|
serve_dir: "/var/gemini"
|
@ -1,7 +1,5 @@
|
|||||||
require 'skeksis'
|
require 'skeksis'
|
||||||
|
|
||||||
SERVE_DIR="/Users/madeline/Code/gemini-bridge-rack/gemini"
|
|
||||||
|
|
||||||
class SkeksisApp
|
class SkeksisApp
|
||||||
def initialize
|
def initialize
|
||||||
@skeksis = Skeksis::GemBridge.new
|
@skeksis = Skeksis::GemBridge.new
|
||||||
@ -10,7 +8,7 @@ class SkeksisApp
|
|||||||
def call(env)
|
def call(env)
|
||||||
status = 200
|
status = 200
|
||||||
headers = { "content-type" => "text/html" }
|
headers = { "content-type" => "text/html" }
|
||||||
body = @skeksis.query(SERVE_DIR + env['PATH_INFO'], env)
|
body = @skeksis.query(env['PATH_INFO'], env)
|
||||||
|
|
||||||
[status, headers, body]
|
[status, headers, body]
|
||||||
end
|
end
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
skeksis_config:
|
|
||||||
gemini_uri: "gemini://gemini.hackers.town/"
|
|
@ -24,15 +24,25 @@ module Skeksis
|
|||||||
|
|
||||||
class GemBridge
|
class GemBridge
|
||||||
def initialize
|
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
|
end
|
||||||
|
|
||||||
def query(path, env)
|
def query(path, env)
|
||||||
if Dir.exist?(path)
|
# Chomps the first / and builds path
|
||||||
#return Dir.each_child(path).map {|i| "#{i}\n"}
|
full_path = Pathname.new(@serve_dir) + path[1..-1]
|
||||||
return create_dir_listing(path, env)
|
puts full_path.to_s
|
||||||
elsif File.exist?(path)
|
if Dir.exist?(full_path)
|
||||||
file = File.open(path, 'r')
|
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
|
data = file.readlines
|
||||||
[htmlize(data, env)]
|
[htmlize(data, env)]
|
||||||
else # path is invalid
|
else # path is invalid
|
||||||
|
@ -60,13 +60,21 @@ module Skeksis
|
|||||||
html
|
html
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# TODO: Relative and absolute links need to be properly handled, both proxied and non
|
||||||
def build_uri(link)
|
def build_uri(link)
|
||||||
uri = URI.parse(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
|
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
|
else
|
||||||
link
|
return link
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user