# I am the Watcher. I am your guide through this vast new twtiverse.
# 
# Usage:
#     https://watcher.sour.is/api/plain/users              View list of users and latest twt date.
#     https://watcher.sour.is/api/plain/twt                View all twts.
#     https://watcher.sour.is/api/plain/mentions?uri=:uri  View all mentions for uri.
#     https://watcher.sour.is/api/plain/conv/:hash         View all twts for a conversation subject.
# 
# Options:
#     uri     Filter to show a specific users twts.
#     offset  Start index for quey.
#     limit   Count of items to return (going back in time).
# 
# twt range = 1 7
# self = https://watcher.sour.is/conv/krgr7ba
I woke up with an extremely silly idea of writing a (yet another) gemini-to-http proxy *but* using some shell boilerplate, gmi2html.awk from prx, and something to fetch them, lol
all through CGI


#!/bin/sh

printf '%s\\n\\r' "Content-type: text/html"

die() {
        printf '%s error: %s\\n\\r' "$(basename "$0")" "$@"
        exit
}

if [ ! "$QUERY_STRING" ]; then
        die "No 'file' parameter"
fi

./gemget -o - "$QUERY_STRING" | ./gmi2html.awk
the result: https://envs.net/~novaburst/gm/index.cgi?file=gemini://dimension.sh/index.gmi

(EDIT: use better example)
https://git.sr.ht/~novaburst-dev/cgi-gemini-proxy

new code:

#!/bin/sh
page="$(echo "$QUERY_STRING" | sed 's/page\\?=//')"
style="https://unpkg.com/sakura.css/css/sakura-dark.css"
title="Aoi's Gemini Proxy - ${page}"
title_err="Aoi's Gemini Proxy - Error"

printf "%s %s\\n\\r" "Content-type: text/html"

if [ -z "$page" ]; then
        echo "<!DOCTYPE html><html><head><link rel=stylesheet href=$style><title>$title_err</title></head>"
        echo "<body><p>Usage: <code>$(basename $0)/page?=gemini://envs.net</code></p><p>Note: This proxy is half-baked on purpose</p>"
        echo "</body></html>"
else
        echo "<!DOCTYPE html><html><head><link rel=stylesheet href=$style><title>$title</title></head>"
        echo "<body>$(./gemget -o - ${page} | ./gmi2html)</body>"
        echo "<br><hr><footer><details><summary>Proxied by <a href=https://git.sr.ht/~novaburst/cgi-gemini-proxy>cgi-gemini-proxy</a></summary></details></footer></body></html>"
fi
also I just realized it can also work w/o the page= parameter, haha