thoughts/tools/doclist

40 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
#
# Generates HTML fragment for document list
#
# Copyright (C) 2013 Mike Gerwitz
#
# 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/>.
##
# ensure extglob is on for !() syntax
shopt -s extglob || exit $?
echo '<ol class="docs">'
# paths are expected to be on their own line
while read f; do
[ -f "$f" ] || continue
# the docs/papers prefix will be stripped from the link and the link title
# will be taken from the first line of the source file; the source file is
# guessed by simply stripping the html suffix off of the filename and
# globbing for any non-html suffix
printf '<li><a href="%s">%s</a></li>\n' \
"${f#docs/papers/}" \
"$( head -n1 "${f%.html}".!(html) )"
done
echo '</ol>'