about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xvienna34
1 files changed, 28 insertions, 6 deletions
diff --git a/vienna b/vienna index 61366bf..b077970 100755 --- a/vienna +++ b/vienna
@@ -263,7 +263,29 @@ phtml() { # phtml < INPUT
263 s#.*#<p>&</p>#' 263 s#.*#<p>&</p>#'
264} 264}
265 265
266meta() { # meta FIELD [FILE] < INPUT 266meta_init() { # meta_init FILE
267 ## Extract metadata from FILE for later processing.
268 # Metadata should exist as colon-separated data in HTML comments in the
269 # input file.
270 metafile=
271 m=false
272 t=false
273 while read -r line; do
274 case "$line" in
275 '<!--') m=true ;;
276 '-->') m=false ;;
277 *title:*) t=true && print "$line" ;;
278 *) "$m" && print "$line" ;;
279 esac
280 done <"$1"
281 if ! "$t"; then
282 title="${1##*/}"
283 title="${title%.*}"
284 print "title: ${title%.*}"
285 fi
286}
287
288meta() { # meta FIELD [FILE]
267 ## Extract metadata FIELDS from INPUT. 289 ## Extract metadata FIELDS from INPUT.
268 # FILE gives the filename to save metadata to in the $WORKD. It 290 # FILE gives the filename to save metadata to in the $WORKD. It
269 # defaults to the current value for $FILE. 291 # defaults to the current value for $FILE.
@@ -271,11 +293,8 @@ meta() { # meta FIELD [FILE] < INPUT
271 # Metadata should exist as colon-separated data in an HTML comment at 293 # Metadata should exist as colon-separated data in an HTML comment at
272 # the beginning of an input file. 294 # the beginning of an input file.
273 field="$1" 295 field="$1"
274 file="${2:-$FILE}" 296 file="${2:-$META}"
275 metafile="${TMPD:=.}/${file}.meta" 297 sed -n "s/^[ \t]*$field:[ \t]*//p" <"$file"
276 test -f "$metafile" ||
277 sed -n '/<!--/!q;/<!--/n;p;/-->/q' >"$metafile"
278 sed -n "s/^[ \t]*$field:[ \t]*//p" <"$metafile"
279} 298}
280 299
281## Customizable bits 300## Customizable bits
@@ -316,7 +335,9 @@ genpage() { # genpage PAGE...
316 outd="$OUTD/${FILE%.$PAGE_RAW_EXT}" 335 outd="$OUTD/${FILE%.$PAGE_RAW_EXT}"
317 outf="$outd/index.html" 336 outf="$outd/index.html"
318 tmpf="$TMPD/$FILE.tmp" 337 tmpf="$TMPD/$FILE.tmp"
338 META="$TMPD/$FILE.meta"
319 mkdir -p "$outd" 339 mkdir -p "$outd"
340 meta_init "$FILE" >"$META"
320 filters <"$FILE" >"$tmpf" 341 filters <"$FILE" >"$tmpf"
321 expand "$PAGE_TEMPLATE" <"$tmpf" >"$outf" 342 expand "$PAGE_TEMPLATE" <"$tmpf" >"$outf"
322 done 343 done
@@ -335,6 +356,7 @@ genlist() { # genlist PERITEM_FUNC TEMPLATE_FILE PAGE...
335 for FILE; do 356 for FILE; do
336 log genlist "$peritem_func" "$FILE" 357 log genlist "$peritem_func" "$FILE"
337 LINK="$DOMAIN${DOMAIN:+/}${FILE%.$PAGE_RAW_EXT}" 358 LINK="$DOMAIN${DOMAIN:+/}${FILE%.$PAGE_RAW_EXT}"
359 META="$TMPD/$FILE.meta"
338 "$peritem_func" "$FILE" 360 "$peritem_func" "$FILE"
339 done | expand "$template_file" 361 done | expand "$template_file"
340} 362}