From bb34d2b128ebc1b95f7cbd40876689707eb1e1e0 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Tue, 17 Mar 2020 16:10:23 +0100 Subject: Initial commit Signed-off-by: David Oberhollenzer --- mk.sh | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100755 mk.sh (limited to 'mk.sh') diff --git a/mk.sh b/mk.sh new file mode 100755 index 0000000..d46f93c --- /dev/null +++ b/mk.sh @@ -0,0 +1,115 @@ +#!/bin/bash + +SCRIPTDIR=$(cd $(dirname "$0") && pwd) +PAGEDIR="$SCRIPTDIR/pages" +IMAGEDIR="$SCRIPTDIR/img" +TEMPLATEDIR="$SCRIPTDIR/templates" +UTILDIR="$SCRIPTDIR/util" +SITEMAP="$(pwd)/sitemap.xml" + +source "$SCRIPTDIR/pagecfg.sh" + +############################################################################### + +pagemenu() { + local current="$1" + local basedir="$(dirname $current)" + + cat "$basedir/menu.csv" | while read line; do + local name=$(echo $line | cut -d, -f1) + local target=$(echo $line | cut -d, -f2) + local template="$TEMPLATEDIR/menu_inactive.html" + + if [[ "$target" =~ ^\./.* ]]; then + target=$(echo $target | sed "s#^./#/${basedir}/#g") + fi + + if [ "$(basename $target)" == "$(basename $current)" ]; then + template="$TEMPLATEDIR/menu_active.html" + fi + + if [[ "$target" =~ \.md$ ]]; then + target=$(echo $target | sed 's/\.md/.html/g') + fi + + sed -e "s#TARGET#$target#g" -e "s#NAME#${name^}#g" "$template" + done +} + +generate_page() { + local mdpath="$1" + local pagename="${2^}" + local longtitle="${3^}" + + sed -e "s#LONG_TITLE#$longtitle#g" \ + -e "s#SHORT_TITLE#$pagename#g" \ + -e "s#STYLESHEET#/$STYLESHEET#g" \ + -e "s#FAVICON#/$FAVICON#g" \ + -e "s#LOGO#/$LOGO#g" \ + -e "s#URL#$URL#g" "$TEMPLATEDIR/page.html" | \ + while read pageline; do + case "$pageline" in + MENU) + pagemenu "$mdpath" + ;; + CONTENT) + markdown "$mdpath" + ;; + COPYRIGHT) + "$UTILDIR/copyright.sh" "$mdpath" + ;; + *) + echo "$pageline" + ;; + esac + done +} + +############################################################################### + +sitemap_begin() { + sed '/ENTRIES/Q' "$TEMPLATEDIR/sitemap.xml" +} + +sitemap_entry() { + "$UTILDIR/sitemap.sh" "$URL" "$1" "$2" + +} + +sitemap_end() { + sed -e '1,/ENTRIES/ d' "$TEMPLATEDIR/sitemap.xml" +} + +############################################################################### +cp "$TEMPLATEDIR/$STYLESHEET" . +cp -r "$IMAGEDIR" . + +sitemap_begin > "$SITEMAP" + +find "$PAGEDIR" -name pages.csv -printf "%P\n" |\ +while read cfgfile; do + cat "$PAGEDIR/$cfgfile" |\ + while read line; do + mdpath="$(dirname $cfgfile)/$(echo $line | cut -d, -f1)" + pagename="$(echo $line | cut -d, -f2)" + longtitle="$(echo $line | cut -d, -f3)" + htmlpath="$(echo $mdpath | sed 's/\.md/.html/g')" + htmlpath_abs="$(pwd)/$htmlpath" + abs_link_path=$(echo "$htmlpath" | sed -e 's#^./##' \ + -e "s#^#/#") + + mkdir -p "$(dirname $htmlpath_abs)" + + pushd "$PAGEDIR" > /dev/null + sitemap_entry "$mdpath" "$abs_link_path" >> "$SITEMAP" + + generate_page "$mdpath" "$pagename" "$longtitle" \ + > "$htmlpath_abs" + popd > /dev/null + done +done + +sitemap_end >> "$SITEMAP" + +cp "$TEMPLATEDIR/robots.txt" . +echo "Sitemap: ${URL%/}/sitemap.xml" >> "robots.txt" -- cgit v1.2.3