From 01ea10f0bf94198031937e439be94c258bef5a1d Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Sun, 19 May 2013 15:56:17 -0400 Subject: [PATCH] Separated index HTML into its own template --- processor | 156 +++++++++++++++++++++++++++--------------------------- repo2html | 3 ++ tpl/index | 28 ++++++++++ 3 files changed, 108 insertions(+), 79 deletions(-) create mode 100755 tpl/index diff --git a/processor b/processor index 2f1b6b7..ef507a0 100755 --- a/processor +++ b/processor @@ -20,102 +20,100 @@ # along with this program. If not, see . # # -repotype="${1?Missing repository type}" -path_out="${2?Missing output path}" +declare -xr repotype="${1?Missing repository type}" +declare -xr path_out="${2?Missing output path}" # provide default message formatter if necessary msgfmt="${msgfmt:-./msgfmt}" # default template path (the former is exported so that templates themselves may # make use of default templates) -export path_default_tpl=./tpl -path_tpl="${path_tpl:-$path_default_tpl}" +declare -xr path_default_tpl=./tpl +declare -xr path_tpl="${path_tpl:-$path_default_tpl}" -# output XHTML5 header -cat < - - - - $title - - -

$title

-

$desc

-EOH +resolv-template() +{ + name="$1" + [ -x "$path_tpl/$name" ] \ + && echo "$path_tpl/$name" \ + || echo "$path_default_tpl/$name" +} +apply-template() +{ + $( resolv-template "$1" ) +} +exec-template() +{ + exec $( resolv-template "$1" ) +} +# performs index generation; by separating this into a procedure, we allow the +# template to invoke it at any point and further process the output +do-index() +{ + prevdate= + lastts= + firstyear=0 + lastyear=0 + lasthash= -prevdate= -lastts= -firstyear=0 -lastyear=0 -lasthash= + # generate index + while read hash commit ts id subject; do + # ignore commits that begin with ':' + [[ "$subject" == :* ]] && { + echo "Ignoring $commit: $subject" >&2 + continue + } -# generate index -while read hash commit ts id subject; do - # ignore commits that begin with ':' - [[ "$subject" == :* ]] && { - echo "Ignoring $commit: $subject" >&2 - continue - } + echo "Found $commit: $subject" >&2 - echo "Found $commit: $subject" >&2 + dateout="$( ./tsdate "$ts" %Y-%m-%d )" + dategroup="${dateout%-*}" + day="${dateout##*-}" + month="$( ./tsdate "$ts" %m )" + year="${dateout%%-*}" - dateout="$( ./tsdate "$ts" %Y-%m-%d )" - dategroup="${dateout%-*}" - day="${dateout##*-}" - month="$( ./tsdate "$ts" %m )" - year="${dateout%%-*}" + # commits are ordered by date desc + lasthash="${lasthash:-$hash}" + lastts="${lastts:-$ts}" + lastyear="${lastyear:-$year}" + firstyear="$year" - # commits are ordered by date desc - lasthash="${lasthash:-$hash}" - lastts="${lastts:-$ts}" - lastyear="${lastyear:-$year}" - firstyear="$year" + pagefile="$( ./outfgen "$ts" "$id" )" + fmtsubject="$( "$msgfmt" < <( echo "$subject"; echo ) )" - pagefile="$( ./outfgen "$ts" "$id" )" - fmtsubject="$( "$msgfmt" < <( echo "$subject"; echo ) )" + [ "$prevdate" == "$dategroup" ] || { + echo "

$dategroup

" + } - [ "$prevdate" == "$dategroup" ] || { - echo "

$dategroup

" - } + printf '' \ + "$day" "$pagefile" "$fmtsubject" - printf '' \ - "$day" "$pagefile" "$fmtsubject" + prevdate="$dategroup" - prevdate="$dategroup" + # create the containing directory (if it does not yet exist and then + # generate the commit page + mkdir -p "$( dirname "$path_out/$pagefile" )" \ + && ( + # make the majority of the data available as environment variables + # (for convenience), lowercase so as not to be conflict with + # conventional environment variables + export hash commit id subject="$fmtsubject" timestamp="$ts" + export dategroup month day year + export path_root='../../' - # create the containing directory (if it does not yet exist and then generate - # the commit page - mkdir -p "$( dirname "$path_out/$pagefile" )" \ - && ( - # make the majority of the data available as environment variables (for - # convenience), lowercase so as not to be conflict with conventional - # environment variables - export hash commit id subject="$fmtsubject" timestamp="$ts" - export dategroup month day year - export path_root='../../' + # invoke template + "$repotype"/commit2html "$commit" | "$path_tpl/commit" + ) > "$path_out/$pagefile" \ + && ./hashcache "$hash" "$pagefile" + done - # invoke template - "$repotype"/commit2html "$commit" | "$path_tpl/commit" - ) > "$path_out/$pagefile" \ - && ./hashcache "$hash" "$pagefile" -done + yearrange="$firstyear" + if [ "$lastyear" -gt "$firstyear" ]; then + yearrange="$firstyear–$lastyear" + fi +} -yearrange="$firstyear" -if [ "$lastyear" -gt "$firstyear" ]; then - yearrange="$firstyear–$lastyear" -fi - -cat <RSS -
-
-
Copyright © $yearrange $copyright
-
Last Updated: $( ./tsdate "$lastts" '%F %H:%M:%S' )
-
$lasthash
-
- - -EOF +# let the template finish +export -f do-index +exec-template index diff --git a/repo2html b/repo2html index 2c79d87..e4eca5a 100755 --- a/repo2html +++ b/repo2html @@ -132,6 +132,9 @@ export cref_errlog=.cref-bad | ./processor "$repotype" "$path_out" 2> >( _reout ) \ ) >/dev/null +# wait for all processes to finish +wait + # if any invalid crefs remain, then they're bad [ ! -s "$cref_errlog" ] || { echo "warning: bad cref(s); see $cref_errlog" >&2 diff --git a/tpl/index b/tpl/index new file mode 100755 index 0000000..53c39a6 --- /dev/null +++ b/tpl/index @@ -0,0 +1,28 @@ +#!/bin/bash +cat < + + + + $title + + +

$title

+

$desc

+EOH + +# generate index and populate statistical vars +do-index + +cat <RSS +
+ + + +EOF