Home | Sitemap

init

This is the first entry of the blog, establishing it for the purpose of some thoughts on an intermediate Linux topics.

Blog Setup

This blog is generated using ssg5 and a little bit of a shell script:

#!/bin/sh

# $1 full refresh
# $2 dest path

if [ $# -le 1 ]; then
    echo
    echo "$0 <full_refresh/wipe> [<dest_path>]"
    echo "  full_refresh: 1/0"
    echo "  dest_path default to /www/blog"
    echo
    exit 1
fi

do_wipe=0
if [ $# -ge 1 ]; then
    do_wipe=$1
fi

if [ $# -ge 2 ]; then
    final_path=$2
else
    final_path=/www/blog
fi

echo "---"
echo "Wipe: ${do_wipe}"
echo "Dest: ${final_path}"
echo "---"

[ ! -e ${final_path} ] && mkdir -p ${final_path}

export PATH="./prebuilt:$PATH"

#set -x
tmpfile=$(mktemp mysite-temp.XXXXXXXX)
touch ${tmpfile}
echo "* Processing blog entries... tmp=${tmpfile}"

blog_html_pages=""
for f in $(ls -r src/blog-*); do
    fname_=${f##src/blog-}
    fname=${fname_%%.md}
    # FIXME: can't do special symbols in titles yet
    ftitle=$(sed -e '/^[^# ]/d' -e '2,$d' -e 's/# \(.*\)$/\1/' $f)
    blog_html_pages="- [${fname}: ${ftitle}](<blog-${fname}.html>)"
    echo "${blog_html_pages}"
done > ${tmpfile}

#echo  "DEBUG:\n${blog_html_pages}"
echo "* Generating blog index..."
awk -v page_content=${tmpfile} '
    /%%BLOG_ENTRIES%%/ { system("cat " page_content); content=1; }
    content { next; }
    {print;}
' template/index.src.md > src/index.md

rm ${tmpfile}

# DEBUG
#echo "--- index.src.md"
#cat template/index.src.md
#echo "--- index.md"
#cat src/index.md
#echo "---"

echo "=== Processing header/footer..."
sed -e "s/%%UPDATE_DATE%%/$(date)/" template/_footer.src.html > src/_footer.html
cp template/_header.html src/_header.html

# generate the pages
# dst is a temporary place we put stuff
# ${final_path} is where the deployment happens

echo "=== Generating pages..."
mkdir -p ${final_path} dst
touch dst/WORKDIR
[ $do_wipe -eq 1 ] && echo "Wipe" && rm -f dst/.files

./prebuilt/ssg5 src dst "Ben's Blog" 'http://'


echo "=== Deploy to www..."
rsync -r -v static/ ${final_path}
rsync -r -v --exclude '.files' --exclude WORKDIR dst/ ${final_path}

echo "Done"

This generates any src/blog-* pages into an index and then inserting it into the index.md page. Then all of it goes through the ssg5 blender to be turned into html pages.

Then rsync is used to deploy everything out.


(C) Copyright 2020-2022 "Ben" Sung Hsu

Updated: Sun Sep 18 12:12:52 PM CDT 2022