diff options
| author | Joe Carstairs <me@joeac.net> | 2026-06-09 16:11:06 +0100 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2026-06-09 16:11:06 +0100 |
| commit | b4f9be57d3afbe19970bb268ecb6723cd80e703e (patch) | |
| tree | 9cc614a387e6811ac8bcd180e774f58f3878c194 /http/bin/blog | |
| parent | 3ecf19cb8aa3661cffbb1ce3e4380807612c446c (diff) | |
http: builds blogs from gemlogs
Diffstat (limited to 'http/bin/blog')
| -rwxr-xr-x | http/bin/blog | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/http/bin/blog b/http/bin/blog new file mode 100755 index 0000000..a16a692 --- /dev/null +++ b/http/bin/blog @@ -0,0 +1,88 @@ +#!/bin/sh -e +export PATH="$(dirname $(realpath $0)):$PATH" +export BLOGS="$(realpath blogs)" +export SRC="$(realpath src)" +export LAYOUTS="$(realpath share/layouts)" + +usage() +{ + >&2 cat << USAGE +usage: blog -i LOG [-l LAYOUT] [-t] + +options: + + -i LOG + The name of the source directory under \$BLOGS where log posts live. + + -l LAYOUT + If provided, the layout under \$LAYOUTS to use for the generated + upphtml files. If not provided, uses the default layout. + + -t + If enabled, use filenames as post titles +USAGE +} + +log_name="" +layout="default" +use_filenames_for_titles=0 + +while getopts "i:l:t" opt +do + case $opt in + i) + log_name="$OPTARG" + ;; + l) + layout_name="$OPTARG" + ;; + t) + use_filenames_for_titles=1 + ;; + esac +done + +if [ -z "${log_name}" ] +then + usage + exit 1 +fi + +if ! [ -d "${BLOGS}/${log_name}" ] +then + >&2 echo "there is no directory '${input_log}' under ${BLOGS}. options: $(ls common)" + usage + exit 1 +fi + +layout="${LAYOUTS}/${layout_name}.layout.upphtml" +if [ "${layout_name}" = "default" ] +then + layout_ext="" +else + layout_ext=".${layout_name}" +fi +if ! [ -f "${layout}" ] +then + echo >&2 "Warning: no layout found at $(basename "${LAYOUTS}")/${layout_name}.layout.upphtml" +fi + +rm -rf "${SRC}/${log_name}/" +mkdir -p "${SRC}/${log_name}" + +for entry in $(find -L "${BLOGS}/${log_name}" -type f) +do + basename="$(basename "$entry")" + name="${basename%%\.*}" + dest="${SRC}/${log_name}/${name}${layout_ext}.upphtml" + if [ $use_filenames_for_titles -eq 1 ] + then + title="$name" + cat "$entry" | gmi2upphtml "$title" > "$dest" + else + title="$(grep --regexp "^\# " --max-count 1 "$entry" | cut -c3-)" + cat "$entry" | grep --regexp "^\# " --invert-match | gmi2upphtml "$title" > "$dest" + fi + echo "${title}" > "${dest}.args" + echo "Processed ${entry#$(dirname ${BLOGS})/} to ${dest#$(dirname ${SRC})/}" +done |
