summaryrefslogtreecommitdiff
path: root/src/html
blob: e00a2b73e0e8a62a5235049d2523513231380566 (plain) (blame)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/bin/sh
set -euo pipefail


usage() {
	echo 'Usage: html [ -H | -F ] FILENAME.htmlbody'
}


HEADER_ONLY=false
FOOTER_ONLY=false
while getopts 'HF' flag; do
	case "$flag" in
		(H)
			HEADER_ONLY=true
			;;
		(F)
			FOOTER_ONLY=true
			;;
		(*)
			usage >&2
			exit 2
			;;
	esac
done
shift $((OPTIND - 1))


FILENAME="${1:-}"
eval "$(assert-arg -- "$FILENAME" 'FILENAME.htmlbody')"
. ./"${FILENAME%.*}.conf"


dates() {
	if [ -z "$date_formatted" ]; then
		return
	fi

	cat <<EOF
        <section id="timestamps">
          <p id="published-at">
            Posted on <time datetime="$date_iso">$date_formatted</time>
          </p>
EOF

	if [ -n "$updatedat_formatted" ]; then
		cat <<EOF
          <p id="updated-at">
            Updated on <time datetime="$updatedat_iso">$updatedat_formatted</time>
          </p>
EOF
	fi

	cat <<EOF
        </section>
EOF
}

h1() {
	if [ "${custombody:-}" = true ]; then
		return
	fi

	cat <<EOF
        <h1>
          $title_html
        </h1>
EOF
}

comments() {
	if [ "${custombody:-}" = true ]; then
		return
	fi

	cat <<EOF
        <section>
          <!-- Use <address> here? -->
          <footer class="content-footer">
            <p id="comment">
              <a href="$comment_url">Comment</a>
              about this page and see
              <a href="$discussions_url">existing discussions</a>
              |
              <a href="$sourcecode_url_prefix/$source_path">view source</a>
            </p>
          </footer>
        </section>
EOF
}


head_meta_author_html=
if [ -n "${author:-}" ]; then
	head_meta_author_html="    <meta name=\"author\"   content=\"$author\" />"
fi


publickey_html=
if [ -n "${publickey:-}" ] && [ -n "${publickey_url:-}" ]; then
	publickey_html="$(cat <<EOF
        <li>
          <picture>
            <source srcset="$lockicon_url_prefix/dark.svg" media="(prefers-color-scheme: dark)" />
            <img       src="$lockicon_url_prefix/light.svg" class="icon" alt="An outlined icon of a lock" />
          </picture>
          <a href="$publickey_url">$publickey</a>
        </li>
EOF
)"
fi



headlinks() {
	echo '        <ol>'

	cat "$header_links" | grep -v '^#' | grep . | while read -r line; do
		link="$(printf '%s\n' "$line" | cut -d'	' -f1)"
		name="$(printf '%s\n' "$line" | cut -d'	' -f2)"
		cat <<EOF
          <li>
            <a href="$base_url_prefix/$link">$name</a>
          </li>
EOF
	done

	echo '        </ol>'
}


collection_head_prev_html=
collection_head_post_html=

header() {
	cat <<EOF | sed '/^$/d'
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
$head_meta_author_html
    <link rel="stylesheet"    type="text/css"             href="$css_url" />
    <link rel="shortcut icon" type="image/svg+xml"        href="$favicon_url" />
    <link rel="canonical"     type="text/html"            href="$url_absolute" />
    <link rel="alternate"     type="application/atom+xml" href="$feed_url" title="$feed_title_html" />
$collection_head_prev_html
$collection_head_post_html
    <title>$titlefull_html</title>
  </head>
  <body>
    <header>
      <nav>
        <a href="$base_url_prefix/">
          <picture>
            <source srcset="$logo_url_prefix/dark.svg" media="(prefers-color-scheme: dark)" />
            <img       src="$logo_url_prefix/light.svg" alt="$logo_alt" />
          </picture>
        </a>
$(headlinks)
      </nav>
      <hr />
    </header>
    <main>
      <article>
EOF

	h1
	dates
}

body() {
	cat "${FILENAME%.*}.htmlbody"
}

footer() {
	comments

	cat <<EOF | sed '/^$/d'
      </article>
    </main>
    <footer>
      <hr />
      <ul>
        <li>
          <picture>
            <source srcset="$envelopeicon_url_prefix/dark.svg" media="(prefers-color-scheme: dark)" />
            <img       src="$envelopeicon_url_prefix/light.svg" class="icon" alt="An outlined icon of an envelope" />
          </picture>
          <a href="mailto:$email">$email</a>
        </li>
$publickey_html
      </ul>
      <p id="license">
        The content for this site is licensed under
        <a rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</a>.
        The <a href="$sourcecode_url/">code</a> is
        <a rel="license" href="$sourcecode_url_prefix/COPYING">AGPLv3 or later</a>.
        Patches welcome.
      </p>
    </footer>
  </body>
</html>
EOF
}


if [ "$HEADER_ONLY" = true ]; then
	header
	exit
fi

if [ "$FOOTER_ONLY" = true ]; then
	footer
	exit
fi

header
body
footer