commit: 143b4a639ad314326b06b357ac8d29f8c8709673
parent 1367775179f437b7f3af4c4eab1ebcb558de9734
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Wed, 4 Nov 2020 10:18:46 +0100
server: Redirect to ${query}/ for directories
Diffstat:
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/server.sh b/server.sh
@@ -30,10 +30,16 @@ then
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 -e 's/ /%20/g' -e "s/^/=> /" 2>/dev/null
+ 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
+ else
+ status="30"
+ printf '30 /%s/\r\n' "$query"
+ fi
else
status="50"
printf '50 File not readable or non-existent\r\n'