logo

gemini-space

What lives at gemini://hacktivis.me/
commit: 75371d2aa236bccbf3127d8c85cf1cfec79b9217
parent 74540a8c79d3f87e9a1afa37831b58bde29280e8
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Wed,  4 Nov 2020 09:15:51 +0100

server.sh: Add auto-indexing

Diffstat:

Mserver.sh14++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/server.sh b/server.sh @@ -10,9 +10,9 @@ IFS=#' ' read -r line # ' hack for vis editor to reset hightlighting… -path="${line#gemini://*/}" -path="${path%%../*}" -path="$GEMDIR/${path:-index.gmi}" +query="${line#gemini://*/}" +query="${query%%../*}" +path="$GEMDIR/${query:-index.gmi}" status="--" if echo $path | egrep -q '.gmi$' @@ -22,11 +22,17 @@ else mime=$(file --mime -b "$path" 2>/dev/null) fi -if [ -r "$path" ] +if [ -r "$path" -a -f "$path" ] then status="20" printf '20 %s\r\n' "$mime" cat "$path" 2>/dev/null +elif [ -r "$path" -a -d "$path" ] +then + status="20" + printf '20 text/gemini; charset=utf-8\r\n' + printf '# Index of %s\n' "$query" + ls "${path}" | sed 's/^/=> /' 2>/dev/null else status="50" printf '50 File not readable or non-existent\r\n'