summaryrefslogtreecommitdiff
path: root/src/html
blob: 72356d09c7cb3065a9fb3c48f60d2381f4d08335 (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
#!/bin/sh
set -euo pipefail


usage() {
	echo 'Usage: html FILENAME.htmlbody'
}

FILENAME="${1:-}"
eval "$(assert-arg -- "$FILENAME" 'FILENAME.htmlbody')"
. "$(realpath -- "${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 [ "${custom_body:-}" = true ]; then
		return
	fi

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

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

	cat <<EOF
        <section>
          <hr />
          <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


headlinks() {
	if [ -z "${header_links:-}" ]; then
		return
	fi

	echo '        <ol>'

	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 < "$header_links"

	echo '        </ol>'
}


collection_head_prev_html=
collection_head_post_html=
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="$atom_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

cat "$FILENAME"

comments

cat <<EOF
      </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>
      </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