summaryrefslogtreecommitdiff
path: root/src/feedentry
blob: 6299e6fee46183bbab0c12be90bc3637736db354 (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
#!/bin/sh
set -euo pipefail


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

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


update_xml=
if [ -n "${updated_at:-}" ]; then
	update_iso="$(date -ud "$updated_at" -Is)"
	update_xml="    <updated>
      $update_iso
    </updated>"
fi

cat <<EOF | sed '/^$/d'
  <entry xml:lang="en">
    <title type="html">
      $title_html
    </title>
    <link type="text/html" rel="alternative" href="$url_absolute" title="$title_html" />
    <published>
      $date_iso
    </published>
$update_xml
    <id>
      $url_absolute
    </id>
    <author>
      <name>
        $author
      </name>
      <email>
        $email
      </email>
    </author>

    <summary type="html">
EOF

head -n5 < "$FILENAME" | htmlesc
printf '    </summary>\n'
printf '    <content type="html" xml:base="%s">\n' "${url:?}"

htmlesc < "$FILENAME"
printf '    </content>\n'
printf '  </entry>\n'