From da5080c53ce8e9e520187e19eeb907c46607b4f0 Mon Sep 17 00:00:00 2001 From: epoch Date: Tue, 1 Feb 2022 03:21:34 +0000 Subject: wikipedia search handler added and normal handler updated --- contrib/wikipedia-handler | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'contrib/wikipedia-handler') diff --git a/contrib/wikipedia-handler b/contrib/wikipedia-handler index 724bda5..c9aaae6 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}" -- cgit v1.2.3