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 ROOT="$HOME/www/mountaineerbr.github.io/"
26
27 ROOTB="$ROOT/blog"
28
29
30 TEMPLATE_POST="$ROOTB/p.html"
31 TEMPLATE_CAT="$ROOTB/c.html"
32
33
34
35 TARGET_TITLES="$ROOTB/titles.txt"
36 TARGET_TITLES_HOME="$ROOTB/titles.homepage.txt"
37
38 TARGET_CAT="$ROOTB/cat.html"
39
40 TARGET_BLOGIND="$ROOTB/index.html"
41
42
43 TARGET_HOME="$ROOT/index.html"
44
45
46
47
48 set -e
49
50
51
52 cd "$ROOTB"
53
54
55 for t in "$TEMPLATE_CAT" "$TEMPLATE_POST"
56 do
57 if [[ ! -f "$t" ]]
58 then
59 echo "template file missing -- $t" >&2
60 exit 1
61 fi
62 done
63 unset t
64
65
66
67 echo 'generate an array with raw post paths..' >&2
68
69
70 while IFS= read
71 do
72 POSTFILE+=( "$REPLY" )
73 done <<< "$( printf '%s\n' */i.html | sort -nr )"
74 unset REPLY
75
76
77 (( ${#POSTFILE[@]} )) || exit 1
78
79
80 [[ ! -f "$TARGET_TITLES" ]] && : > "$TARGET_TITLES"
81
82
83 echo 'compile index.html files for individual posts..' >&2
84 n="${#POSTFILE[@]}"
85 for f in "${POSTFILE[@]}"
86 do
87
88
89
90 targetpost="${f/i.html/index.html}"
91
92
93 TARGETPOST_TEMP="${targetpost}.part"
94
95
96 sed -n '/<head>/,/<\/head>/ p' "$f" |
97 sed 's/^<\/*head>// ; /^\s*$/d' |
98 sed '/^<!-- metatags -->/ r /dev/stdin' "$TEMPLATE_POST" > "$TARGETPOST_TEMP"
99
100
101 sed -n '/<article.*>/,/<\/article>/ p' "$f" |
102 sed '/^<!-- article -->/ r /dev/stdin' "$TARGETPOST_TEMP" > "$targetpost"
103
104
105
106
107
108
109 TAGPX='<!-- postlistX -->'
110 TARGET_TITLES_TEMP="${TARGET_TITLES}.new"
111 {
112
113 ((n==${#POSTFILE[@]})) && echo "$TAGPX"
114
115
116
117
118 if tili="$( sed -nE 's|(.*<title>)([^"]+)<.*|\2| p' "$f" | sed 's|\s--\sBiol.*||' )"
119 ! grep -Fi "$tili" "$TARGET_TITLES"
120 then
121
122 <<< "$tili" sed "s|^|<li><a href=\"${f%\/*}\/\">|g" |
123 sed 's|$|</a></li>|g'
124 fi
125
126
127 ((n==1)) && echo "$TAGPX"
128
129 } >> "$TARGET_TITLES_TEMP"
130
131
132 ((--n))
133
134
135 unset f TARGETPOST_TEMP targetpost s ss sss tili tile
136
137 done || true
138
139
140 mv -fv "$TARGET_TITLES_TEMP" "$TARGET_TITLES"
141
142
143 rm -v -- */*.part
144
145
146
147
148 echo 'compile cat.html with all posts..' >&2
149
150
151
152
153 sed -n '/<article.*>/,/<\/article>/ p' "${POSTFILE[@]}" |
154 sed '/^<!-- articles -->/ r /dev/stdin' "$TEMPLATE_CAT" > "$TARGET_CAT"
155
156
157
158 sed -i 's/<article.*>/<br><br>\n&/' "$TARGET_CAT"
159
160
161
162
163
164 s='(href|src)='
165 ss='="\.\.\/'
166 sss='="'
167 sed -Ei -e "/${s}/ { /favicon.ico/! s|${ss}|${sss}|g }" \
168 -e 's|href=""|href="./"|g' \
169 "$TARGET_CAT"
170
171
172
173
174
175
176
177
178 sed -i "/$TAGPX/,/$TAGPX/ d" "$TARGET_BLOGIND"
179 sed -i "/^\s*<!-- postlist -->/ r $TARGET_TITLES" "$TARGET_BLOGIND"
180
181
182
183
184
185
186 sed 's|href="|href="blog/|' "$TARGET_TITLES" |
187 sed '11,$ s|<li>.*|| ; /^$/ d' > "$TARGET_TITLES_HOME"
188
189
190 sed -i "/$TAGPX/,/$TAGPX/ d" "$TARGET_HOME"
191 sed -i "/^\s*<!-- postlist -->/ r $TARGET_TITLES_HOME" "$TARGET_HOME"
192
193
194
195
196
197
198
199
200
201
202
203 TODO
204