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
parent
7965009bd4
commit
033baae96a
32
repo2html
32
repo2html
|
@ -20,6 +20,12 @@
|
|||
# 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
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
@ -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 "<h2 id="$dategrp">$dategrp</h2>"
|
||||
[ "$lastdate" == "$dategroup" ] || {
|
||||
echo "<h2 id="$dategroup">$dategroup</h2>"
|
||||
}
|
||||
|
||||
printf '<ul><li>(%02d) <a href="%s">%s</a></li></ul>' \
|
||||
"$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
|
||||
)
|
||||
|
|
2
rss
2
rss
|
@ -46,7 +46,7 @@ while read -r commit ts id subject; do
|
|||
<item>
|
||||
<title><![CDATA[$( ./msgfmt < <( echo "$subject"; echo ) )]]></title>
|
||||
<link>
|
||||
$( printf "%s/%(%Y)T/%(%m)T/%s.html" "$url" "$ts" "$ts" "$id" )
|
||||
$( printf "%s/%(%Y/%m)T/%s.html" "$url" "$ts" "$id" )
|
||||
</link>
|
||||
<pubDate>$( date --date="1970-01-01 $ts sec" +%Y-%m-%d )</pubDate>
|
||||
<description>
|
||||
|
|
|
@ -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 © %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>
|
|
@ -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 © $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
|
Loading…
Reference in New Issue