-- Leo's gemini proxy

-- Connecting to git.thebackupbox.net:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

repo: uritools
action: commit
revision:
path_from:
revision_from: da5080c53ce8e9e520187e19eeb907c46607b4f0:
path_to:
revision_to:

git.thebackupbox.net

uritools

git://git.thebackupbox.net/uritools

commit da5080c53ce8e9e520187e19eeb907c46607b4f0
Author: epoch <epoch@enzo.thebackupbox.net>
Date:   Tue Feb 1 03:21:34 2022 +0000

    wikipedia search handler added and normal handler updated

diff --git a/contrib/Makefile b/contrib/Makefile

index 53667f63bc2a5c0b3e5548ab307d5fb0e64d5d73..

index ..06b2d9cc833d7f48cdb9df34edf6cdb21b37f4e0 100644

--- a/contrib/Makefile
+++ b/contrib/Makefile
@@ -7,4 +7,5 @@ all:

 install:
 	install -Dt $(PREFIX)/bin wikipedia-handler
+	install -Dt $(PREFIX)/bin wikipedia-search-handler
 	install -Dt ~/.config/uristart.conf.d/ wikipedia.uristart.conf
diff --git a/contrib/wikipedia-handler b/contrib/wikipedia-handler

index 724bda5c7a9b44bffa10510c7db52f8e0d272a99..

index ..c9aaae6de4d82640b788c2bd52770ac920b738f7 100755

--- a/contrib/wikipedia-handler
+++ b/contrib/wikipedia-handler
@@ -1,10 +1,13 @@
 #!/usr/bin/env bash
-xmessage "loading page for: $1"
 page="$(uriescape "$1")"
 cache_file=~/.cache/wikipedia/"${page}.pdf"
 mkdir -p ~/.cache/wikipedia
 ## follow redirects (-L), silent (-s), and no globbing (-g), you can guess what -H does.
 last_modified="$(rfc7231date "$(stat -c '%Y' "${cache_file}")")"
-curl -H "If-Modified-Since: ${last_modified}" -L -s -g "https://en.wikipedia.org/api/rest_v1/page/pdf/${page}" -o "${cache_file}"
+if [ "$last_modified" ];then
+  curl -H "If-Modified-Since: ${last_modified}" -L -s -g "https://en.wikipedia.org/api/rest_v1/page/pdf/${page}" -o "${cache_file}"
+else
+  curl -L -s -g "https://en.wikipedia.org/api/rest_v1/page/pdf/${page}" -o "${cache_file}"
+fi
 fileuri=file://"${cache_file}"
 uristart "${fileuri}"
diff --git a/contrib/wikipedia-search-handler b/contrib/wikipedia-search-handler
new file mode 100755
index 0000000000000000000000000000000000000000..72f051fcf8bab5245e61280de807f026d0082847
--- /dev/null
+++ b/contrib/wikipedia-search-handler
@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+uri="$1"
+shortened="$(unshorten.sh "${uri}")"
+if [ "${shortened}" ];then
+  uri="${shortened}"
+fi
+shortened="$(unshorten.sh "${uri}")"
+if [ "${shortened}" ];then
+  uri="${shortened}"
+  uristart "$uri"
+else
+  curl -g "$uri" | grep '^<i>The page "<a href="/w/index' | sed 's|<i>\([^<]\)</i>||g' | tr '<' '\n' \
+    | grep ^a \
+    | cut '-d"' -f2 \
+    | sed 's|^/|https://en.wikipedia.org/|g' \
+    | text_uri-list
+fi

-----END OF PAGE-----

-- Response ended

-- Page fetched on Sun Jun 2 15:34:36 2024