summary refs log tree commit diff stats
path: root/fwendplanet_html.awk
blob: 654a9391e7ae0d139f60e90f3d03c92fd8725fcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/awk -f
# Convert sfeed(1) formatted files into an HTML webpage for fwends
# Usage: sfeed_html.awk -- FILES...
BEGIN {
	TITLE = "fwend planet"
	FS = "\t"
	NEXT = ENVIRON["NEXT"]
	PREV = ENVIRON["PREV"]
}

BEGIN {
	print "<!DOCTYPE html>"
	print "<html>"
	print "<head>"
	print "<meta charset=\"utf-8\">"
	print "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">"
	print "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">"
	print "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"
	print "<title>" TITLE "</title>"
	print "<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">"
	print "</head>"
	print "<body>"
	print "<div id=\"main\">"
	print "<h1>fwend planet"
	if (PREV) {
		p = (PREV ~ /index/ ? 1 : PREV)
		gsub(/[^0-9]/, "", p)
		print "p. " (int(p) + 1)
	}
	print "</h1>"
	print "<div class=\"nav\">"
	if (PREV) {
		print "<a href=\"" PREV "\">prev</a>"
	}
	if (NEXT) {
		print "<a href=\"" NEXT "\">next</a>"
	}
	print "</div>"
}

{
	# Collect fields
	timestamp = $1
	title = $2
	link = $3
	content = unescape($4)
	content_type = $5
	id = $6
	author = $7
	enclosure = $8
	category = $9
	datecmd = "date -d@" timestamp " +%F"
	datecmd | getline date
	close(datecmd)
	print "<details>"
	print "<summary>" (title ? title : "<untitled>")
	print " : <time class=\"time\">" date "</time>"
	print "<div class=\"clearfix\"></div></summary>"
	print "<div class=\"links\">"
	if (link && title !~ /linkbudz/ && link != enclosure) {
		print "<a href=\"" link "\">read original</a>"
	}
	if (enclosure) {
		print "<a href=\"" enclosure "\">enclosure</a>"
	}
	print "</div>"
	print "<div class=\"content\">" content "</div>"
	print "<details class=\"info\"><summary>item information</summary>"
	print "<dl>"
	print "<dt>timestamp</dt><dd>" timestamp "</dd>"
	print "<dt>title</dt><dd>" title "</dd>"
	print "<dt>link</dt><dd>" link "</dd>"
	print "<dt>content_type</dt><dd>" content_type "</dd>"
	print "<dt>id</dt><dd>" id "</dd>"
	print "<dt>author</dt><dd>" author "</dd>"
	print "<dt>enclosure</dt><dd>" enclosure "</dd>"
	print "<dt>category</dt><dd>" category "</dd>"
	print "</dl>"
	print "</details>"
	print "</details>"
}

END {
	print "<div class=\"nav\">"
	if (PREV) {
		print "<a href=\"" PREV "\">prev</a>"
	}
	if (NEXT) {
		print "<a href=\"" NEXT "\">next</a>"
	}
	print "</div>"
	print "<div id=\"footer\">"
	print "sourced from <a href=\"https://tildegit.org/casa/pages/src/branch/main/opml/mug.of.opml\">"
	print "a mug of opml</a>."
	print "<a href=\"mailto:fwends@me.acdw.net\">problems? suggestions?</a>"
	print "</div>"
	print "</div>"
	print "</body>"
	print "</html>"
}


function unescape(t)
{
	gsub(/\\t/, "\t", t)
	gsub(/\\n/, "\n", t)
	gsub(/\\\\/, "\\", t)
	return t
}