summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorepoch <epoch@enzo.thebackupbox.net>2022-02-01 01:24:14 +0000
committerepoch <epoch@enzo.thebackupbox.net>2022-02-01 01:24:14 +0000
commit0608408fbc36dae25ab5cc114fb51b622ecc5937 (patch)
treed524c27c8d281bf75a412236908989bae301e808
parent8e26db47a0ec223c0ae19ed23b56599c962d3bc1 (diff)
downloaduritools-0608408fbc36dae25ab5cc114fb51b622ecc5937.tar.gz
uritools-0608408fbc36dae25ab5cc114fb51b622ecc5937.zip
wikipedia-handler
-rw-r--r--contrib/Makefile10
-rwxr-xr-xcontrib/wikipedia-handler10
-rw-r--r--contrib/wikipedia.uristart.conf1
3 files changed, 21 insertions, 0 deletions
diff --git a/contrib/Makefile b/contrib/Makefile
new file mode 100644
index 0000000..53667f6
--- /dev/null
+++ b/contrib/Makefile
@@ -0,0 +1,10 @@
+.PHONEY: install all
+
+PREFIX:=/usr/local
+
+all:
+ echo nothing whatever
+
+install:
+ install -Dt $(PREFIX)/bin wikipedia-handler
+ install -Dt ~/.config/uristart.conf.d/ wikipedia.uristart.conf
diff --git a/contrib/wikipedia-handler b/contrib/wikipedia-handler
new file mode 100755
index 0000000..724bda5
--- /dev/null
+++ b/contrib/wikipedia-handler
@@ -0,0 +1,10 @@
+#!/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}"
+fileuri=file://"${cache_file}"
+uristart "${fileuri}"
diff --git a/contrib/wikipedia.uristart.conf b/contrib/wikipedia.uristart.conf
new file mode 100644
index 0000000..7a5936e
--- /dev/null
+++ b/contrib/wikipedia.uristart.conf
@@ -0,0 +1 @@
+s https d en.wikipedia.org p /wiki/*: wikipedia-handler "$(printf "%%s\n" '%p' | sed 's|^/wiki/||')"