2012-10-07 11:43:41 -04:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Generates HTML from repository commit messages
|
|
|
|
#
|
|
|
|
# Copyright (C) 2012 Mike Gerwitz
|
|
|
|
#
|
|
|
|
# This file is part of repo2html.
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
# #
|
|
|
|
|
|
|
|
repotype="${1?Missing repository type}"
|
|
|
|
path_out="${2?Missing output path}"
|
|
|
|
|
|
|
|
cat <<EOH
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
2012-10-08 22:19:55 -04:00
|
|
|
<link rel="alternate" title="RSS Feed"
|
|
|
|
href="rss.xml" type="application/rss+xml" />
|
2012-10-07 16:44:12 -04:00
|
|
|
<title>$title</title>
|
2012-10-07 11:43:41 -04:00
|
|
|
</head>
|
|
|
|
<body>
|
2012-10-07 16:44:12 -04:00
|
|
|
<h1>$title</h1>
|
|
|
|
<h2>$desc</h2>
|
2012-10-07 11:43:41 -04:00
|
|
|
EOH
|
|
|
|
|
|
|
|
|
|
|
|
prevdate=
|
|
|
|
lastts=
|
|
|
|
firstyear=
|
|
|
|
lastyear=
|
|
|
|
lasthash=
|
|
|
|
|
|
|
|
# generate index
|
|
|
|
while read hash commit ts id subject; do
|
2012-10-08 22:19:55 -04:00
|
|
|
echo "[HTML] Found $commit: $subject" >&2
|
2012-10-07 11:43:41 -04:00
|
|
|
|
|
|
|
dateout="$( printf "%(%Y-%m-%d)T" "$ts" )"
|
|
|
|
dategroup="${dateout%-*}"
|
|
|
|
day="${dateout##*-}"
|
|
|
|
month="$( printf "%(%m)T" "$ts" )"
|
|
|
|
year="${dateout%%-*}"
|
|
|
|
|
|
|
|
# commits are ordered by date desc
|
|
|
|
lasthash="${lasthash:-$hash}"
|
|
|
|
lastts="${lastts:-$ts}"
|
|
|
|
lastyear="${lastyear:-$year}"
|
|
|
|
firstyear="$year"
|
|
|
|
|
|
|
|
pagefile="$year/$month/$id.html"
|
|
|
|
fmtsubject="$( ./msgfmt < <( echo "$subject"; echo ) )"
|
|
|
|
|
|
|
|
[ "$prevdate" == "$dategroup" ] || {
|
2012-10-07 16:44:12 -04:00
|
|
|
echo "<h3 id="$dategroup">$dategroup</h3>"
|
2012-10-07 11:43:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
printf '<ul><li>(%02d) <a href="%s">%s</a></li></ul>' \
|
|
|
|
"$day" "$pagefile" "$fmtsubject"
|
|
|
|
|
|
|
|
prevdate="$dategroup"
|
|
|
|
|
|
|
|
# create the containing directory (if it does not yet exist and then generate
|
|
|
|
# the commit page
|
|
|
|
mkdir -p "$( dirname "$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
|
2012-10-08 22:19:55 -04:00
|
|
|
export path_root='../../'
|
2012-10-07 11:43:41 -04:00
|
|
|
|
|
|
|
# invoke template
|
|
|
|
"$repotype"/commit2html "$commit" | ./tpl/commit.sh
|
|
|
|
) > "$path_out/$pagefile"
|
|
|
|
done
|
|
|
|
|
|
|
|
yearrange="$firstyear"
|
|
|
|
if [ "$lastyear" -gt "$firstyear" ]; then
|
|
|
|
yearrange="$firstyear–$lastyear"
|
|
|
|
fi
|
|
|
|
|
|
|
|
cat <<EOF
|
2012-10-08 22:19:55 -04:00
|
|
|
<div id="rss"><a href="rss.xml">RSS</a></div>
|
2012-10-07 11:43:41 -04:00
|
|
|
<hr />
|
|
|
|
<footer>
|
2012-10-07 16:44:12 -04:00
|
|
|
<div>Copyright © $yearrange $copyright</div>
|
2012-10-07 11:43:41 -04:00
|
|
|
<div>Last Updated: $( printf "%(%F %H:%M:%S)T" "$lastts" )</div>
|
|
|
|
<div>$lasthash</div>
|
|
|
|
</footer>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
EOF
|