logo

gemini-space

What lives at gemini://hacktivis.me/
commit: 77c31a5ef01716ba5febec26aa37aa4fe8cfa751
parent c8c056a7ad21b32a945d6e795ce65a81858ffa26
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon, 30 Nov 2020 00:33:00 +0100

server.sh: Support for multi-host and subdir indexes

Diffstat:

Mserver.sh21++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)

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