summaryrefslogtreecommitdiff
path: root/plain.sh
blob: 482b55cca91fdaac590b0c4f220557bab528d85c (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
#!/bin/sh
set -e

# usage: ./plain.sh <input txt> <output html>

# Copyright 2019-2022 DistressNetwork° <uplink@distress.network>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


[ "$1" ] || { echo "usage: ./plain.sh <input txt> <output html>" ; exit 1 ; }

[ -f "$1" ] || { printf "[err] \tFATAL: %s not found\n" "$1" ; exit 1 ; }
[ -f plain-header ] || { printf "[err] \tFATAL: plain-header not found\n" ; exit 1 ; }


cat plain-header > "$2"
cat "$1" >> "$2"
printf "</pre>\n</body>\n</html>" >> "$2"
printf "[ok] \tinitial assembly\n"

# hack to fix double <pre> when generating from nav.sh
sed -e "/^<pre>$/ {n;/^<pre>$/d}" -e "/^<\/pre>$/ {n;/^<\/pre>$/d}" -i'' "$2"


sedesc() {
	sed -e 's;\&;\\\&;' -e 's/;/\\\;/' -e 's;-->;;'
}

TITLE=$(grep -e '^<!--title: ' -m 1 $1 | cut -f 2- -d ' ' | sedesc)
sed -e "/^<!--title:/d" -e "s;<title>#;<title>${TITLE};1" -i'' "$2"
printf "[ok] \ttitle: %s\n" "$TITLE"

MDATE=$(stat -c '%y' "$1" | sed -e 's/\.[0-9]* //' -e 's/\(..\)\(..\)$/\1:\2/') # format: "yyyy-mm-dd hh:mm:ss±zz:zz" (ISO 8601)
sed "s;<meta http-equiv=\"last-modified\" content=\";&${MDATE};1" -i'' "$2"
printf "[ok] \tdate: %s\n" "$MDATE"


printf "%s \tbuild complete: %s\n" "[->]" "$2"