X-Git-Url: https://plomlompom.com/repos/?p=redo-blog;a=blobdiff_plain;f=processor%2Fmetadata%2Fdefault.intermediate.do;h=bf87309575ba431c31d95327d762bbe831b89671;hp=adcd2eb93b065d70db7ad7250aa4198ea2627958;hb=ff5b37d8bc4cfba8f1db69a279da887accaa0296;hpb=f88948caf952c4fd913ea7466c2f1ab3455af506 diff --git a/processor/metadata/default.intermediate.do b/processor/metadata/default.intermediate.do index adcd2eb..bf87309 100644 --- a/processor/metadata/default.intermediate.do +++ b/processor/metadata/default.intermediate.do @@ -1,15 +1,28 @@ #!/bin/sh +# Pull in dependencies. template=intermediate.pandoc_tmpl -uuidfile="${1%.intermediate}.uuid" -redo-ifchange "$uuidfile" +meta_file="${1%.intermediate}.automatic_metadata" +redo-ifchange "$meta_file" redo-ifchange "$template" mdfile="../${1%.intermediate}.md" rstfile="../${1%.intermediate}.rst" + +# Build intermediate file. if [ -f "$rstfile" ]; then redo-ifchange "$rstfile" - pandoc -f rst --template="$template" --mathml -t html5 "$rstfile" > "$3" + pandoc -f rst --template="$template" --mathml -t html5 "$rstfile" --base-header-level=2 > "$3" elif [ -f "$mdfile" ]; then redo-ifchange "$mdfile" - pandoc -f markdown --template="$template" --mathml -t html5 "$mdfile" > "$3" + pandoc -f markdown --template="$template" --mathml -t html5 "$mdfile" --base-header-level=2 > "$3" +fi + +# Update meta file if appropriate. +md5_new=$(md5sum "$3" | cut -d ' ' -f 1) +md5_old=$(cat "$meta_file" | sed -n '3p') +if [ ! "$md5_new" = "$md5_old" ]; then + new_date=$(date -u "+%s") + sed -i '1,2!d' "$meta_file" + echo "$md5_new" >> "$meta_file" + echo "$new_date" >> "$meta_file" fi