feed.sh - 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
---
feed.sh
---
1 #!/bin/sh
2
3
4 #
5 # Render RSS/Atom feed as a gph using sfeed
6 #
7 feed_to_gph()
8 {
9
10 sfeed |
11 awk -v feed_author="${FEED_AUTHOR}" \
12 -v feed_date="${FEED_DATE}" \
13 -v feed_content="${FEED_CONTENT}" \
14 -v cgi="${ARTICLE_CGI}" \
15 -F '\t' '
16 function print_content(c, c_type)
17 {
18 gsub("\\\\n", "\n", c)
19 gsub("\\\\t", " ", c)
20 gsub("\\\\\\\\", "\\", c)
21
22 # Nonexistent proxy to block HTTP requests
23 cmd = "http_proxy=\"http://localhost:31283128\""
24
25 # UTF-8
26 cmd = cmd " LANG=en_US.UTF-8"
27
28 if (c_type == "html") {
29 cmd = cmd " w3m -T text/html"
30 } else {
31 cmd = cmd " w3m -T text/plain"
32 }
33 cmd = cmd " -config /dev/null"
34 cmd = cmd " -dump -no-cookie -cols 72"
35 cmd = cmd " -o display_link=false"
36 cmd = cmd " -o display_link_number=false"
37 cmd = cmd " -o display_image=false"
38 cmd = cmd " -o pseudo_inlines=false"
39
40 cmd = cmd " | sed -e \"s/^/t/\""
41
42 print c | cmd
43 close(cmd)
44 }
45
46 {
47 timestamp = $1
48 title = $2
49 link = $3
50 content = $4
51 content_type = $5
52 id = $6
53 author = $7
54
55 desc = title
56 if (feed_author && author) {
57 desc = desc ", " author
58 }
59 if (feed_date && timestamp) {
60 desc = sprintf("%s (%s)", desc,
61 strftime("%Y-%m-%d", timestamp))
62 }
63
64 gsub("\\|", "\\|", desc)
65 gsub("\\|", "\\|", cgi)
66 gsub("\\|", "\\|", link)
67
68 if (cgi) {
69 printf("[0|%s|%s?%s|server|port]\n", desc, cgi, link)
70 } else {
71 printf("[h|%s|URL:%s|server|port]\n", desc, link)
72 }
73
74 if (feed_content && content) {
75 print ""
76 print_content(content, content_type)
77 print ""
78 print ""
79 }
80 }
81 '
82 }