Add initial support for pagination (ATM only `Previous page' is supported). - gophercgis - Collection of gopher CGI/DCGI for geomyidae (HTM) hg clone https://bitbucket.org/iamleot/gophercgis (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) changeset 4e44e9ad56b30c075bc1e2107e3947ac468cd4f0 (DIR) parent 9d2b1f1e54dbf72200bb8c3558e758359882da88 (HTM) Author: Leonardo Taccari <iamleot@gmail.com> Date: Wed, 8 Aug 2018 12:52:14 Add initial support for pagination (ATM only `Previous page' is supported). Diffstat: reddit/r.dcgi | 27 +++++++++++++++++++++++---- 1 files changed, 23 insertions(+), 4 deletions(-) --- diff -r 9d2b1f1e54db -r 4e44e9ad56b3 reddit/r.dcgi --- a/reddit/r.dcgi Wed Aug 08 10:21:15 2018 +0200 +++ b/reddit/r.dcgi Wed Aug 08 12:52:14 2018 +0200 @@ -1,10 +1,21 @@ #!/bin/sh +CGI="/cgi/reddit/r.dcgi" COMMENTS_CGI="/cgi/reddit/c.dcgi" -subreddit="$2" +case "$2" in +*/*) + subreddit="${2%%/*}" + after="${2##*/}" + url="https://www.reddit.com/r/${subreddit}/.json?after=${after}" + ;; +*) + subreddit="${2}" + url="https://www.reddit.com/r/${subreddit}/.json" + ;; +esac + ua="" -url="https://www.reddit.com/r/${subreddit}/.json" echo "t" echo "tr/${subreddit}" @@ -12,12 +23,20 @@ /usr/pkg/bin/curl -A "${ua}" -s "${url}" | /usr/pkg/bin/jq -r ' -.data.children[] | .data | +( .data.children[] | .data | "[h|\(.title | gsub("\\|"; "\\|") )|" + "URL:\(.url | gsub("\\|"; "\\|"))|server|port]", "t\(.author) \( .created_utc | strftime("%F %H:%M") )", "tScore: \(.score)", "[1|Comments: \(.num_comments)|" + "'"${COMMENTS_CGI}?${subreddit}/"'" + "\(.id)|server|port]", - "t" + "t" ), +( if .data.after != "" then + "[1|<< Previous page|" + + "'"${CGI}?${subreddit}/"'" + "\(.data.after)|server|port]" + else + empty + end, + "t" +) '