From 830f63641b40152dc42ea4632e8e0c06788cfa11 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Wed, 17 Jun 2026 09:52:43 +0100 Subject: factors out prune_blog to bin --- http/bin/prune_blog | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 http/bin/prune_blog (limited to 'http/bin') diff --git a/http/bin/prune_blog b/http/bin/prune_blog new file mode 100755 index 0000000..35f7c3c --- /dev/null +++ b/http/bin/prune_blog @@ -0,0 +1,42 @@ +#!/bin/sh -e + +BLOG="$1" + +SRC="$(realpath src)" +BLOGS="$(realpath blogs)" +LAYOUTS="$(realpath share/layouts)" +BLOG_DIR_IN_SRC="${SRC}/${BLOG}" +BLOG_EXT=gmi + +for post in $(find "$BLOG_DIR_IN_SRC" -type f) +do + last_segment="${post##*\.}" + if [ "$last_segment" = "args" ] + then + continue + fi + + post_rel_path="$(echo "$post" | cut -c${#BLOG_DIR_IN_SRC}- | cut -c3-)" + post_basename="${post_rel_path::${#post_rel_path}-${#last_segment}-1}" + post_src="${BLOGS}/${BLOG}/${post_basename}.${BLOG_EXT}" + if [ -f "$post_src" ] + then + continue + fi + + penultimate_segment="${post::${#post}-${#last_segment}-1}" + penultimate_segment="${penultimate_segment##*\.}" + post_basename="${post_rel_path::${#post_rel_path}-${#last_segment}-${#penultimate_segment}-2}" + if [ -f "${LAYOUTS}/${penultimate_segment}.layout.${last_segment}" ] + then + post_basename="${post_rel_path::${#post_rel_path}-${#last_segment}-${#penultimate_segment}-2}" + post_src="${BLOGS}/${BLOG}/${post_basename}.${BLOG_EXT}" + if [ -f "$post_src" ] + then + continue + fi + fi + + echo "No source file found to match post ${post} in blog ${BLOG}: removing ${post}" + rm "$out" +done -- cgit v1.2.3