#!/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"