commit 436bd0dddf7f76fbe68b52ff6fa34e3af18ba68a
parent 643416930ced9b240f147c34a8536d239405c311
Author: Byron Torres <b@torresjrjr.com>
Date: Thu, 11 Nov 2021 00:56:24 +0000
Use POSIX sh, various fixes
Diffstat:
M | pdssg | | | 35 | +++++++++++++++++++++-------------- |
1 file changed, 21 insertions(+), 14 deletions(-)
diff --git a/pdssg b/pdssg
@@ -1,11 +1,12 @@
-#!/usr/bin/sh
+#!/bin/sh
# pdssg - pandoc static site generator
# Makes a static site with Atom feeds.
main() {
echo "### Begin compiling ###"
+ date
- prepare_dst
+ prepare_dst "$1"
find_feeds
for post_dir in ${POSTS_DIRS}
@@ -23,7 +24,7 @@ main() {
echo
echo "### End compiling ###"
- echo
+ date
}
@@ -31,10 +32,12 @@ main() {
prepare_dst() {
NOW_DATETIME="$(date -uIs)"
+
+ ROOTDIR="$1"
+ cd "$ROOTDIR"
echo
echo "# Preparing ./dst/ directory"
- echo :: $(pwd)
[ -d ./src/ ] || {
echo "No ./src/ directory, exiting"
@@ -45,13 +48,15 @@ prepare_dst() {
copiable=$(
find ./src/ \
-maxdepth 1 \
- -regex '\./src/[^.].*' \
+ -regex '\./src/_.*'
+ find ./src/ \
+ -maxdepth 1 \
+ -regex '\./src/[^._].*' \
-newer ./src/.last_build
)
[ -n "$copiable" ] && cp -rv $copiable ./dst
cd ./dst/
- echo :: $(pwd)
echo "Preparing temporary directory for cache"
# NOTE: POPF (Point Of Potential Failure)
@@ -125,19 +130,22 @@ cache_posts_metadata() {
posts_dir=$1
cache_file="${TMP_DIR}/${posts_dir}/meta.yaml"
- echo -e "Preparing cache file:\t${cache_file}"
+ env printf 'Preparing cache file: %s\n' "${cache_file}"
mkdir -p $(dirname ${cache_file})
echo "log:" > ${cache_file}
for post in ${posts_dir}/*.md
do
- echo -e "Caching:\t${post}"
+ env printf 'Caching: %s\n' "${post}"
post_yaml="$(_get_yaml_block ${post})"
filename=$(basename ${post})
slug_attr="slug: ${filename%.md}"
- yaml_block="$(echo -e "${post_yaml}\n${slug_attr}" | sed 's/^/ /')"
+ yaml_block="$(
+ env printf '%s\n' "${post_yaml}" "${slug_attr}" \
+ | sed 's/^/ /'
+ )"
echo " -" >> ${cache_file}
echo "${yaml_block}" >> ${cache_file}
@@ -155,7 +163,7 @@ process_files() {
for md_file in $@
do
- echo -e "Processing:\t${md_file}"
+ env printf 'Processing: %s\n' "${md_file}"
### prepare flags for pandoc conversion ###
new_filepath=${md_file%.md}.html
@@ -228,7 +236,7 @@ make_atom_feed() {
posts_reverse=$(echo ${posts_dir}/*.html | sed 's/ /\n/g' | sort -r)
for post in ${posts_reverse}
do
- echo -e "Inserting:\t${post}"
+ env printf 'Inserting: %s\n' "${post}"
sed -n '/<!--CONTENT-->/,$!p' ${TMP_DIR}/atom.xml > ${TMP_DIR}/before.xml
cat "${post}" | sed -n '/<article>/,/<\/article>/p' > ${TMP_DIR}/content.xml
@@ -244,7 +252,7 @@ clearup_files() {
echo
echo "# Clearing up Markdown files"
- rm -v $@
+ [ $# -gt 0 ] && rm -v "$@"
rm -rv $( find . -regex '.*/_.*' | sort -r )
}
@@ -253,7 +261,6 @@ finish() {
echo "# Finished compiling"
cd ..
- echo :: $(pwd)
echo "Finished"
}
@@ -284,5 +291,5 @@ _get_safe_slug() {
# main
-main
+main "$@"