Separated index HTML into its own template
parent
67bd586ecd
commit
01ea10f0bf
88
processor
88
processor
|
@ -20,40 +20,45 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
# #
|
# #
|
||||||
|
|
||||||
repotype="${1?Missing repository type}"
|
declare -xr repotype="${1?Missing repository type}"
|
||||||
path_out="${2?Missing output path}"
|
declare -xr path_out="${2?Missing output path}"
|
||||||
|
|
||||||
# provide default message formatter if necessary
|
# provide default message formatter if necessary
|
||||||
msgfmt="${msgfmt:-./msgfmt}"
|
msgfmt="${msgfmt:-./msgfmt}"
|
||||||
|
|
||||||
# default template path (the former is exported so that templates themselves may
|
# default template path (the former is exported so that templates themselves may
|
||||||
# make use of default templates)
|
# make use of default templates)
|
||||||
export path_default_tpl=./tpl
|
declare -xr path_default_tpl=./tpl
|
||||||
path_tpl="${path_tpl:-$path_default_tpl}"
|
declare -xr path_tpl="${path_tpl:-$path_default_tpl}"
|
||||||
|
|
||||||
# output XHTML5 header
|
resolv-template()
|
||||||
cat <<EOH
|
{
|
||||||
<!DOCTYPE html>
|
name="$1"
|
||||||
<html>
|
[ -x "$path_tpl/$name" ] \
|
||||||
<head>
|
&& echo "$path_tpl/$name" \
|
||||||
<link rel="alternate" title="RSS Feed"
|
|| echo "$path_default_tpl/$name"
|
||||||
href="rss.xml" type="application/rss+xml" />
|
}
|
||||||
<title>$title</title>
|
apply-template()
|
||||||
</head>
|
{
|
||||||
<body>
|
$( resolv-template "$1" )
|
||||||
<h1>$title</h1>
|
}
|
||||||
<h2>$desc</h2>
|
exec-template()
|
||||||
EOH
|
{
|
||||||
|
exec $( resolv-template "$1" )
|
||||||
|
}
|
||||||
|
|
||||||
|
# performs index generation; by separating this into a procedure, we allow the
|
||||||
|
# template to invoke it at any point and further process the output
|
||||||
|
do-index()
|
||||||
|
{
|
||||||
|
prevdate=
|
||||||
|
lastts=
|
||||||
|
firstyear=0
|
||||||
|
lastyear=0
|
||||||
|
lasthash=
|
||||||
|
|
||||||
prevdate=
|
# generate index
|
||||||
lastts=
|
while read hash commit ts id subject; do
|
||||||
firstyear=0
|
|
||||||
lastyear=0
|
|
||||||
lasthash=
|
|
||||||
|
|
||||||
# generate index
|
|
||||||
while read hash commit ts id subject; do
|
|
||||||
# ignore commits that begin with ':'
|
# ignore commits that begin with ':'
|
||||||
[[ "$subject" == :* ]] && {
|
[[ "$subject" == :* ]] && {
|
||||||
echo "Ignoring $commit: $subject" >&2
|
echo "Ignoring $commit: $subject" >&2
|
||||||
|
@ -86,13 +91,13 @@ while read hash commit ts id subject; do
|
||||||
|
|
||||||
prevdate="$dategroup"
|
prevdate="$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
|
||||||
# the commit page
|
# generate the commit page
|
||||||
mkdir -p "$( dirname "$path_out/$pagefile" )" \
|
mkdir -p "$( dirname "$path_out/$pagefile" )" \
|
||||||
&& (
|
&& (
|
||||||
# make the majority of the data available as environment variables (for
|
# make the majority of the data available as environment variables
|
||||||
# convenience), lowercase so as not to be conflict with conventional
|
# (for convenience), lowercase so as not to be conflict with
|
||||||
# environment variables
|
# conventional environment variables
|
||||||
export hash commit id subject="$fmtsubject" timestamp="$ts"
|
export hash commit id subject="$fmtsubject" timestamp="$ts"
|
||||||
export dategroup month day year
|
export dategroup month day year
|
||||||
export path_root='../../'
|
export path_root='../../'
|
||||||
|
@ -101,21 +106,14 @@ while read hash commit ts id subject; do
|
||||||
"$repotype"/commit2html "$commit" | "$path_tpl/commit"
|
"$repotype"/commit2html "$commit" | "$path_tpl/commit"
|
||||||
) > "$path_out/$pagefile" \
|
) > "$path_out/$pagefile" \
|
||||||
&& ./hashcache "$hash" "$pagefile"
|
&& ./hashcache "$hash" "$pagefile"
|
||||||
done
|
done
|
||||||
|
|
||||||
yearrange="$firstyear"
|
yearrange="$firstyear"
|
||||||
if [ "$lastyear" -gt "$firstyear" ]; then
|
if [ "$lastyear" -gt "$firstyear" ]; then
|
||||||
yearrange="$firstyear–$lastyear"
|
yearrange="$firstyear–$lastyear"
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
cat <<EOF
|
# let the template finish
|
||||||
<div id="rss"><a href="rss.xml">RSS</a></div>
|
export -f do-index
|
||||||
<hr />
|
exec-template index
|
||||||
<footer>
|
|
||||||
<div>Copyright © $yearrange $copyright</div>
|
|
||||||
<div>Last Updated: $( ./tsdate "$lastts" '%F %H:%M:%S' )</div>
|
|
||||||
<div>$lasthash</div>
|
|
||||||
</footer>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
EOF
|
|
||||||
|
|
|
@ -132,6 +132,9 @@ export cref_errlog=.cref-bad
|
||||||
| ./processor "$repotype" "$path_out" 2> >( _reout ) \
|
| ./processor "$repotype" "$path_out" 2> >( _reout ) \
|
||||||
) >/dev/null
|
) >/dev/null
|
||||||
|
|
||||||
|
# wait for all processes to finish
|
||||||
|
wait
|
||||||
|
|
||||||
# if any invalid crefs remain, then they're bad
|
# if any invalid crefs remain, then they're bad
|
||||||
[ ! -s "$cref_errlog" ] || {
|
[ ! -s "$cref_errlog" ] || {
|
||||||
echo "warning: bad cref(s); see $cref_errlog" >&2
|
echo "warning: bad cref(s); see $cref_errlog" >&2
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
#!/bin/bash
|
||||||
|
cat <<EOH
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<link rel="alternate" title="RSS Feed"
|
||||||
|
href="rss.xml" type="application/rss+xml" />
|
||||||
|
<title>$title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>$title</h1>
|
||||||
|
<h2>$desc</h2>
|
||||||
|
EOH
|
||||||
|
|
||||||
|
# generate index and populate statistical vars
|
||||||
|
do-index
|
||||||
|
|
||||||
|
cat <<EOF
|
||||||
|
<div id="rss"><a href="rss.xml">RSS</a></div>
|
||||||
|
<hr />
|
||||||
|
<footer>
|
||||||
|
<div>Copyright © $yearrange $copyright</div>
|
||||||
|
<div>Last Updated: $( ./tsdate "$lastts" '%F %H:%M:%S' )</div>
|
||||||
|
<div>$lasthash</div>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
EOF
|
Loading…
Reference in New Issue