From 033baae96afd549253557f13e31753bdd5566d7f Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Sun, 7 Oct 2012 11:01:32 -0400 Subject: [PATCH] Using shell script for commit template The majority of the data is exposed via the environment and the actual body is piped to the script. This change allows for a great deal of flexibility with regards to templating---users may write "templates" in whatever language they choose to generate whatever output they wish. We should do as much processing beforehand as possible so that the template does not need to, for example, start snooping through the repos (which will be more complicated once we support multiple VCSs). --- repo2html | 32 +++++++++++++++++++------------- rss | 2 +- tpl/commit.html | 24 ------------------------ tpl/commit.sh | 30 ++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 38 deletions(-) delete mode 100644 tpl/commit.html create mode 100755 tpl/commit.sh diff --git a/repo2html b/repo2html index 8a4b1f8..c0d63ca 100755 --- a/repo2html +++ b/repo2html @@ -20,6 +20,12 @@ # along with this program. If not, see . # # +path_out="$( pwd )" +path="$( dirname "$0" )" +cd "$path" + +export GIT_DIR="$path_out/.git" + cat < @@ -40,7 +46,7 @@ while read hash commit ts id subject; do echo "Found $commit: $subject" >&2 dateout="$( printf "%(%Y-%m-%d)T" "$ts" )" - dategrp="${dateout%-*}" + dategroup="${dateout%-*}" day="${dateout##*-}" month="$( printf "%(%m)T" "$ts" )" year="${dateout%%-*}" @@ -52,28 +58,28 @@ while read hash commit ts id subject; do pagefile="$year/$month/$id.html" fmtsubject="$( ./msgfmt < <( echo "$subject"; echo ) )" - [ "$lastdate" == "$dategrp" ] || { - echo "

$dategrp

" + [ "$lastdate" == "$dategroup" ] || { + echo "

$dategroup

" } printf '' \ "$day" "$pagefile" "$fmtsubject" - lastdate="$dategrp" + lastdate="$dategroup" # create the containing directory (if it does not yet exist and then generate # the commit page mkdir -p "$( dirname "$pagefile" )" \ && ( - printf "$( cat tpl/commit.html )" \ - "$fmtsubject" \ - "$fmtsubject" \ - "$ts" \ - "$( ./hash2html "$commit" )" \ - "$dategrp" \ - "$year" \ - "$hash" - ) > "$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 + + # invoke template + ./hash2html "$commit" | ./tpl/commit.sh + ) > "$path_out/$pagefile" done < <( git log --pretty='format:%H %h %at %f %s' && echo ) diff --git a/rss b/rss index 069a511..1efe00a 100755 --- a/rss +++ b/rss @@ -46,7 +46,7 @@ while read -r commit ts id subject; do <![CDATA[$( ./msgfmt < <( echo "$subject"; echo ) )]]> - $( printf "%s/%(%Y)T/%(%m)T/%s.html" "$url" "$ts" "$ts" "$id" ) + $( printf "%s/%(%Y/%m)T/%s.html" "$url" "$ts" "$id" ) $( date --date="1970-01-01 $ts sec" +%Y-%m-%d ) diff --git a/tpl/commit.html b/tpl/commit.html deleted file mode 100644 index 6c61a67..0000000 --- a/tpl/commit.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - %s - - -

%s

-

%(%Y-%m-%d)T

- %s - -

- (Return to index) -

- -
-
- Copyright © %d Mike Gerwitz. - Verbatim redistribution of this document in its entirety is permitted so - long as this copyright notice is preserved. - -
%s
-
- - diff --git a/tpl/commit.sh b/tpl/commit.sh new file mode 100755 index 0000000..1216f2f --- /dev/null +++ b/tpl/commit.sh @@ -0,0 +1,30 @@ +#!/bin/bash +cat < + + + $subject + + +

$subject

+

$year-$month-$day

+ +
+ $( cat ) +
+ +

+ (Return to index) +

+ +
+ + + +EOF