1
0
Fork 0

The processor is now VCS-agnostic

Git calls have been abstracted such that any detected VCS may be used. Of
course, I only have interest in Git at present, so it is my hope that anyone
else interested in this project will contribute.
master
Mike Gerwitz 2012-10-07 11:43:41 -04:00
parent 9bf3831c28
commit dd6c1679e5
No known key found for this signature in database
GPG Key ID: F22BB8158EE30EAB
4 changed files with 140 additions and 78 deletions

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# #
# Outputs formatted HTML for the given hash # Outputs formatted HTML for the given commit hash
# #
# Copyright (C) 2012 Mike Gerwitz # Copyright (C) 2012 Mike Gerwitz
# #

24
git/list 100755
View File

@ -0,0 +1,24 @@
#!/bin/sh
#
# Outputs parsable commit list for Git repositories
#
# 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/>.
# #
# add an extra newline to prevent read from getting confused
git log --pretty='format:%H %h %at %f %s' && echo

100
processor 100755
View File

@ -0,0 +1,100 @@
#!/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>
<title>Mike Gerwitz's Thoughts and Ramblings</title>
</head>
<body>
<h1>Mike Gerwitz's Thoughts and Ramblings</h1>
EOH
prevdate=
lastts=
firstyear=
lastyear=
lasthash=
# generate index
while read hash commit ts id subject; do
echo "Found $commit: $subject" >&2
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" ] || {
echo "<h2 id="$dategroup">$dategroup</h2>"
}
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
# invoke template
"$repotype"/commit2html "$commit" | ./tpl/commit.sh
) > "$path_out/$pagefile"
done
yearrange="$firstyear"
if [ "$lastyear" -gt "$firstyear" ]; then
yearrange="$firstyear&ndash;$lastyear"
fi
cat <<EOF
<hr />
<footer>
<div>Copyright &copy; $yearrange Mike Gerwitz</div>
<div>Last Updated: $( printf "%(%F %H:%M:%S)T" "$lastts" )</div>
<div>$lasthash</div>
</footer>
</body>
</html>
EOF

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# #
# Generates HTML from repository commit messages (currently Git only) # Detects repository VCS and begins VCS-specific processing
# #
# Copyright (C) 2012 Mike Gerwitz # Copyright (C) 2012 Mike Gerwitz
# #
@ -20,83 +20,21 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# # # #
# repository detection
repotype=
if repodir="$( git rev-parse --git-dir 2>/dev/null )"; then
# use absolute path for git directory
export GIT_DIR="$( cd $repodir && pwd )"
repotype=git
else
# contribute!
echo "fatal: only git repositories are currently supported" >&2
exit 128
fi
path_out="$( pwd )" path_out="$( pwd )"
path="$( dirname "$0" )" path="$( dirname "$0" )"
cd "$path" cd "$path"
export GIT_DIR="$path_out/.git" # pass commit list to the processor
"$repotype"/list | ./processor "$repotype" "$path_out"
cat <<EOH
<!DOCTYPE html>
<html>
<head>
<title>Mike Gerwitz's Thoughts and Ramblings</title>
</head>
<body>
<h1>Mike Gerwitz's Thoughts and Ramblings</h1>
EOH
lastdate=
firstyear=
lastyear=
# generate index
while read hash commit ts id subject; do
echo "Found $commit: $subject" >&2
dateout="$( printf "%(%Y-%m-%d)T" "$ts" )"
dategroup="${dateout%-*}"
day="${dateout##*-}"
month="$( printf "%(%m)T" "$ts" )"
year="${dateout%%-*}"
# commits are ordered by date desc
lastyear="${lastyear:-$year}"
firstyear="$year"
pagefile="$year/$month/$id.html"
fmtsubject="$( ./msgfmt < <( echo "$subject"; echo ) )"
[ "$lastdate" == "$dategroup" ] || {
echo "<h2 id="$dategroup">$dategroup</h2>"
}
printf '<ul><li>(%02d) <a href="%s">%s</a></li></ul>' \
"$day" "$pagefile" "$fmtsubject"
lastdate="$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
# invoke template
./hash2html "$commit" | ./tpl/commit.sh
) > "$path_out/$pagefile"
done < <(
git log --pretty='format:%H %h %at %f %s' && echo
)
yearrange="$firstyear"
if [ "$lastyear" -gt "$firstyear" ]; then
yearrange="$firstyear&ndash;$lastyear"
fi
cat <<EOF
<hr />
<footer>
<div>Copyright &copy; $yearrange Mike Gerwitz</div>
<div>Last Updated: $( date )</div>
<div>$( git log --pretty=format:%H | head -n1 )</div>
</footer>
</body>
</html>
EOF