From 5b13b2259caf34a7ef2f46ee645ee6f3afae3c96 Mon Sep 17 00:00:00 2001 From: Malin Freeborn Date: Wed, 15 Apr 2026 11:25:07 +0200 Subject: [PATCH] rework article command --- Makefile | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 090fd30..fc6da42 100644 --- a/Makefile +++ b/Makefile @@ -76,29 +76,6 @@ default += .git/info/exclude .PHONY: database database: $(default) ## Make a recfiles database -%.md: - printf '---\n' - printf 'title: "%s"\n' "$(title)" - printf 'tags: [ "%s" ]\n' "$(shell echo $(basename $(dir $@)) | sed 's/\/$$//' )" | tr '[:upper:]' '[:lower:]' | sed 's#\/#", "#g' - printf 'requires: [ ]\n' - printf '---\n' - -ifdef title -col = blue -path = $(shell find $(categories) -type d | sort | uniq | $(FZF)) -filename = $(shell echo "$(title)" | tr ' ' '_' | tr -cd '[:alnum:]_') -endif - -title = $(shell read -r -p "Title: " line && echo "$${line}" | tr -d '"' | sed 's/\b\(.\)/\U\1/g') - -.PHONY: .entry -.entry: $(path)/$(filename).md - -.PHONY: article -article: ## Write an article - make -e title="$(title)" .entry - - .dbs/map.fmt:| .dbs/ printf '%s\n' '[ {{requires[0]}} ] --> [ {{title}} ] {border-style: dashed;}' > $@ printf '%s\n' '[ {{requires[1]}} ] --> [ {{title}} ] {border-style: dashed;}' >> $@ @@ -114,3 +91,24 @@ map: db.rec .dbs/map.fmt ## Show knowledge dependency map .PHONY: clean clean: ## Remove all generated files $(RM) $(default) + +.PHONY: article +article: **/ **/**/ ## Write a new article + category=$(shell echo $^ | tr ' ' '\n' | $(FZF) ) \ + && read -p "Article title? " name \ + && filename="$$(echo "$$name" \ + | cut -d: -f1 \ + | tr -cd '[:alpha:]' | tr '[A-Z ]' '[a-z_]' )" \ + && $(MAKE) -e TITLE="$$name" "$$category"/"$$filename.md" + +%.md: + [ -d "$(@D)" ] || mkdir $(@D) + printf '%s\n' '---' >> $@ + printf 'title: %s\n' '$(TITLE)' >> $@ + tags="$$(echo $(@D) | sed 's#/$$#"# ; s#/#", "#g ; s#^#"#' )" \ + && printf 'tags [ %s ]\n' "$$tags" >> $@ + printf '%s\n\n' '---' >> $@ + $(EDITOR) +5 $@ + git add $@ + git commit -m"article: $(TITLE)" +