summaryrefslogtreecommitdiff
path: root/http
diff options
context:
space:
mode:
authorJoe Carstairs <me@joeac.net>2026-06-17 09:52:43 +0100
committerJoe Carstairs <me@joeac.net>2026-06-17 09:56:48 +0100
commit830f63641b40152dc42ea4632e8e0c06788cfa11 (patch)
treec7b48ae3693fe0b4ef4533cd6ea3957f73ae3e65 /http
parent3e0def43051f03a6a2e81c81cd4ffe413d86444e (diff)
factors out prune_blog to bin
Diffstat (limited to 'http')
-rw-r--r--http/Makefile20
-rwxr-xr-xhttp/bin/prune_blog42
2 files changed, 44 insertions, 18 deletions
diff --git a/http/Makefile b/http/Makefile
index da2a8d6..8d0d82a 100644
--- a/http/Makefile
+++ b/http/Makefile
@@ -7,29 +7,13 @@ prune: prune_microlog prune_blog prune_out
prune_out:
./bin/prune_out
-.SILENT: prune_microlog
.PHONY: prune_microlog
prune_microlog:
- for post in $$(find src/microlog -name *.microlog.upphtml); do \
- post_basename="$$(basename "$$post")"; \
- post_src="blogs/microlog/$${post_basename::$${#post_basename}-17}.gmi"; \
- if ! [ -f "$$post_src" ]; then \
- echo "Microlog post source file $${post_src} has been deleted: removing $${post}"; \
- rm -f "$$post" "$${post}.args"; \
- fi; \
- done
+ ./bin/prune_blog microlog
-.SILENT: prune_blog
.PHONY: prune_blog
prune_blog:
- for post in $$(find src/blog -name *.blog.upphtml); do \
- post_basename="$$(basename "$$post")"; \
- post_src="blogs/blog/$${post_basename::$${#post_basename}-13}.gmi"; \
- if ! [ -f "$$post_src" ]; then \
- echo "Blog post source file $${post_src} has been deleted: removing $${post}"; \
- rm -f "$$post" "$${post}.args"; \
- fi; \
- done
+ ./bin/prune_blog blog
src_files := $(filter-out %.args,$(wildcard src/*.upp*))
src_files += $(filter-out %.args,$(wildcard src/**/*.upp*))
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