From f09bbf8d4aa5b18b0298b66aa132325232c6ba54 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Thu, 25 Jun 2026 09:49:14 +0100 Subject: [PATCH] replaces prune_blog script with http/Makefile rules --- http/Makefile | 43 ++++++++++++++++++++++++------------------- http/bin/prune_blog | 45 --------------------------------------------- 2 files changed, 24 insertions(+), 64 deletions(-) delete mode 100755 http/bin/prune_blog diff --git a/http/Makefile b/http/Makefile index e789c8f..511f523 100644 --- a/http/Makefile +++ b/http/Makefile @@ -5,8 +5,7 @@ include config.mk # VARIABLES # ############# -src_files := $(filter-out %.args,$(wildcard src/*.upp*)) -src_files += $(filter-out %.args,$(wildcard src/**/*.upp*)) +src_files := $(filter-out %.args,$(wildcard src/*.upp*)) $(filter-out %.args,$(wildcard src/**/*.upp*)) src_files_ext := $(suffix $(src_files)) out_deps_ext := $(src_files_ext:.upp%=%) @@ -14,10 +13,10 @@ component_files := $(shell find -L share/components -type f) layout_files := $(wildcard share/layouts/*.layout.upp*) layouts := $(notdir $(basename $(basename $(layout_files)))) -out_deps := $(addprefix out/,$(src_files:src/%=%)) -remove_layout_from_out_deps = out_deps := $$(subst $(1).upp,.,$$(out_deps)) -$(foreach layout,$(layouts),$(eval $(call remove_layout_from_out_deps,.$(layout)))) -$(eval $(call remove_layout_from_out_deps,)) +remove_all_layouts = $(call remove_layouts,$(layouts),$(1)) +remove_layouts = $(let first rest,$(1),$(call remove_layout,$(first),$(if $(rest),$(call remove_layouts,$(rest),$(2)),$(2)))) +remove_layout = $(subst .$(1).upp,.,$(2)) +out_deps := $(subst .upp,.,$(call remove_all_layouts,$(addprefix out/,$(src_files:src/%=%)))) out_deps_without_src := $(filter-out $(out_deps),$(shell find -L out -type f)) out_deps += $(out_deps_without_src) @@ -34,6 +33,7 @@ blog_src = $(patsubst \ blogs/$(blog)/%.$(BLOG_EXT_$(blog)),\ src/$(blog)/%$(if $(BLOG_LAYOUT_$(blog)),.$(BLOG_LAYOUT_$(blog))).upphtml,\ $(shell find -L "blogs/$(blog)" -type f -and -name *.$(BLOG_EXT_$(blog)))) +blog_src_without_post_src = $(filter-out $(blog_src),$(shell find -L "src/$(blog)" -type f -and -name *.$(BLOG_LAYOUT_$(blog)).upphtml)) default_layout_file = $(if \ $(shell [ -f "share/layouts/default.layout.$(ext)" ] && echo 1),\ share/layouts/default.layout.$(ext)) @@ -51,7 +51,7 @@ endef define blog_rule = .PHONY: $(blog) -$(blog): $(blog_src) +$(blog): $(blog_src_without_post_src) $(blog_src) endef define blog_post_rule = @@ -63,6 +63,20 @@ $(blog_post_target): $(blog_post_src) $(let ext,html,$(layout_file) $(component_ -f $$*.$(BLOG_EXT_$(blog)) endef +define prune_blog_src_file_rule = +$(let rel_basename,$(patsubst src/$(blog)/%.$(BLOG_LAYOUT_$(blog)).upphtml,%,$(file)), +blogs/$(blog)/$(rel_basename).$(BLOG_EXT_$(blog)): + rm $(file) +) +endef + +define prune_blog_out_file_rule = +$(let rel_basename,$(patsubst src/$(blog)/%.$(BLOG_LAYOUT_$(blog)).upphtml,%,$(file)), +$(file): + rm out/$(rel_basename).html +) +endef + define prune_out_file_rule = $(let orig_ext,$(patsubst .%,%,$(suffix $(file))), $(let ext,$(patsubst upp%,%,$(orig_ext)), @@ -75,18 +89,13 @@ $(src_file) $(src_files_with_layouts) $(public_file): )))))) endef -define prune_blog_rule = -.PHONY: prune_$(blog) -prune_$(blog): - ./bin/prune_blog $(blog) *$(if $(BLOG_LAYOUT_$(blog)),.$(BLOG_LAYOUT_$(blog))).upphtml -endef - ######### # RULES # ######### -all: bin/pp prune $(blogs) public out vendor +all: bin/pp $(blogs) public out vendor + $(MAKE) out # if blog posts have been pruned, outfiles must be re-calculated bin/pp: cd pp && $(MAKE) && cp pp ../bin/pp @@ -119,12 +128,8 @@ public: $(subst public/,out/,$(shell find -L public/ -type f)) out/%: public/% mkdir -p $(dir $@) && cp $< $@ -.PHONY: prune -prune: $(addprefix prune_,$(blogs)) - $(foreach file,$(out_deps_without_src),$(eval $(prune_out_file_rule))) - -$(foreach blog,$(blogs),$(eval $(prune_blog_rule))) +$(foreach blog,$(blogs),$(foreach file,$(blog_src_without_post_src),$(eval $(prune_blog_src_file_rule)))) vendor: composer.json composer.lock composer install diff --git a/http/bin/prune_blog b/http/bin/prune_blog deleted file mode 100755 index 849b293..0000000 --- a/http/bin/prune_blog +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh -e - -BLOG="$1" -BLOG_POST_PATTERN="${2:-*}" - -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 -and -name "$BLOG_POST_PATTERN") -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_len=$(( ${#post_rel_path} - ( ${#last_segment} + 1 ) )) - post_basename="$(echo "${post_rel_path}" | cut -c1-${post_basename_len})" - post_src="${BLOGS}/${BLOG}/${post_basename}.${BLOG_EXT}" - if [ -f "$post_src" ] - then - continue - fi - - penultimate_segment_len=$(( ${#post} - ( ${#last_segment} + 1 ) )) - penultimate_segment="$(echo "${post}" | cut -c1-${penultimate_segment_len})" - penultimate_segment="${penultimate_segment##*\.}" - post_basename_len=$(( ${#post_rel_path} - ( ${#last_segment} + ${#penultimate_segment} + 2 ) )) - post_basename="$(echo "${post_rel_path}" | cut -c1-${post_basename_len})" - if [ -f "${LAYOUTS}/${penultimate_segment}.layout.${last_segment}" ] - then - 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 -f "$post" "${post}.args" -done