openbsd-webzine/issues/tools/make_issue.sh

55 lines
967 B
Bash
Raw Normal View History

2021-09-26 19:27:49 +00:00
#!/bin/sh
usage() {
2021-10-01 00:26:50 +00:00
echo "$0 directory"
2021-09-26 19:27:49 +00:00
exit 1
}
die() {
echo "$1"
exit 1
}
testsite=0
if [ "$1" = "-t" ]
then
testsite=1
shift
fi
2021-09-26 19:27:49 +00:00
DIR=$(basename $1)
DESTFILENAME=$2
2021-09-26 19:27:49 +00:00
CURINODE=$(stat -f "%i" current/)
test -d "$DIR" || usage
test -d ../public/ || die "You must run this from openbsd-webzine/current"
ls $DIR/*.html 2>&1 >/dev/null || die "no html file in $DIR"
2021-09-29 16:44:26 +00:00
. ./${DIR}/metadata.sh
if [ "$testsite" -eq 0 ] && [ "$(stat -f '%i' $DIR)" -eq "$CURINODE" ]
2021-09-26 19:27:49 +00:00
then
DEST=dev
else
DEST=public
fi
if test -z "$DESTFILENAME"
then
DESTFILENAME="../${DEST}/${DIR}.html"
fi
cat _common/header $DIR/*html _common/footer > $DESTFILENAME
2021-09-26 21:53:43 +00:00
2021-09-30 20:29:18 +00:00
if ! [ "$DIR" = "_index" ]
then
# replace with issue number
issue="${1#issue-}"
sed -i "s/__ISSUE__/${issue}/g" $DESTFILENAME
else
sed -i "s/OpenBSD_WEBZINE_ISSUE #__ISSUE__/The OpenBSD Webzine/g" $DESTFILENAME
fi
2021-09-26 21:53:43 +00:00
# replace date
2021-09-29 16:44:26 +00:00
sed -i "s/__DATE__/${PUBLISHED_DATE}/" $DESTFILENAME