1
0
Fork 0

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).
master
Mike Gerwitz 2012-10-07 11:01:32 -04:00
parent 7965009bd4
commit 033baae96a
No known key found for this signature in database
GPG Key ID: F22BB8158EE30EAB
4 changed files with 50 additions and 38 deletions

View File

@ -20,6 +20,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# # # #
path_out="$( pwd )"
path="$( dirname "$0" )"
cd "$path"
export GIT_DIR="$path_out/.git"
cat <<EOH cat <<EOH
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@ -40,7 +46,7 @@ while read hash commit ts id subject; do
echo "Found $commit: $subject" >&2 echo "Found $commit: $subject" >&2
dateout="$( printf "%(%Y-%m-%d)T" "$ts" )" dateout="$( printf "%(%Y-%m-%d)T" "$ts" )"
dategrp="${dateout%-*}" dategroup="${dateout%-*}"
day="${dateout##*-}" day="${dateout##*-}"
month="$( printf "%(%m)T" "$ts" )" month="$( printf "%(%m)T" "$ts" )"
year="${dateout%%-*}" year="${dateout%%-*}"
@ -52,28 +58,28 @@ while read hash commit ts id subject; do
pagefile="$year/$month/$id.html" pagefile="$year/$month/$id.html"
fmtsubject="$( ./msgfmt < <( echo "$subject"; echo ) )" fmtsubject="$( ./msgfmt < <( echo "$subject"; echo ) )"
[ "$lastdate" == "$dategrp" ] || { [ "$lastdate" == "$dategroup" ] || {
echo "<h2 id="$dategrp">$dategrp</h2>" echo "<h2 id="$dategroup">$dategroup</h2>"
} }
printf '<ul><li>(%02d) <a href="%s">%s</a></li></ul>' \ printf '<ul><li>(%02d) <a href="%s">%s</a></li></ul>' \
"$day" "$pagefile" "$fmtsubject" "$day" "$pagefile" "$fmtsubject"
lastdate="$dategrp" lastdate="$dategroup"
# create the containing directory (if it does not yet exist and then generate # create the containing directory (if it does not yet exist and then generate
# the commit page # the commit page
mkdir -p "$( dirname "$pagefile" )" \ mkdir -p "$( dirname "$pagefile" )" \
&& ( && (
printf "$( cat tpl/commit.html )" \ # make the majority of the data available as environment variables (for
"$fmtsubject" \ # convenience), lowercase so as not to be conflict with conventional
"$fmtsubject" \ # environment variables
"$ts" \ export hash commit id subject="$fmtsubject" timestamp="$ts"
"$( ./hash2html "$commit" )" \ export dategroup month day year
"$dategrp" \
"$year" \ # invoke template
"$hash" ./hash2html "$commit" | ./tpl/commit.sh
) > "$pagefile" ) > "$path_out/$pagefile"
done < <( done < <(
git log --pretty='format:%H %h %at %f %s' && echo git log --pretty='format:%H %h %at %f %s' && echo
) )

2
rss
View File

@ -46,7 +46,7 @@ while read -r commit ts id subject; do
<item> <item>
<title><![CDATA[$( ./msgfmt < <( echo "$subject"; echo ) )]]></title> <title><![CDATA[$( ./msgfmt < <( echo "$subject"; echo ) )]]></title>
<link> <link>
$( printf "%s/%(%Y)T/%(%m)T/%s.html" "$url" "$ts" "$ts" "$id" ) $( printf "%s/%(%Y/%m)T/%s.html" "$url" "$ts" "$id" )
</link> </link>
<pubDate>$( date --date="1970-01-01 $ts sec" +%Y-%m-%d )</pubDate> <pubDate>$( date --date="1970-01-01 $ts sec" +%Y-%m-%d )</pubDate>
<description> <description>

View File

@ -1,24 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>%s</title>
</head>
<body>
<h1>%s</h1>
<h2>%(%Y-%m-%d)T</h2>
%s
<p>
<a href="../../../#%s">(Return to index)</a>
</p>
<hr />
<footer>
Copyright &copy; %d Mike Gerwitz.
Verbatim redistribution of this document in its entirety is permitted so
long as this copyright notice is preserved.
<div>%s</div>
</footer>
</body>
</html>

30
tpl/commit.sh 100755
View File

@ -0,0 +1,30 @@
#!/bin/bash
cat <<EOF
<!DOCTYPE html>
<html>
<head>
<title>$subject</title>
</head>
<body>
<h1>$subject</h1>
<h2>$year-$month-$day</h2>
<div id="body">
$( cat )
</div>
<p>
<a href="$path_root#$dategroup">(Return to index)</a>
</p>
<hr />
<footer>
Copyright &copy; $year Mike Gerwitz.
Verbatim redistribution of this document in its entirety is permitted so
long as this copyright notice is preserved.
<div>$hash</div>
</footer>
</body>
</html>
EOF