diff --git a/Makefile b/Makefile index 95113b0..8297a8e 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,7 @@ default += .dbs/map.fmt echo '*' > $@.gitignore include cmd.mk +include pub.mk .dbs/head.rec: | .dbs/ printf '%s\n' '%rec: guide' > $@ @@ -100,7 +101,7 @@ map: .dbs/requires.rec .dbs/map.fmt ## Show knowledge dependency map .PHONY: clean clean: ## Remove all generated files - $(RM) -r $(default) .dbs/ + $(RM) -r $(default) .dbs/ .publish/ .PHONY: article article: */ */*/ ## Write a new article diff --git a/cmd.mk b/cmd.mk index 2c96221..bbc2e37 100644 --- a/cmd.mk +++ b/cmd.mk @@ -1,23 +1,4 @@ -cmds != recsel command.rec -t command -G bin -CP bin | sort -u -lists = $(patsubst %,lists/%.md, $(cmds)) - -get_title = printf 'title: %s\n' '${1}' -get_tags = recsel -t $(basename $<) $< -G bin \ - -e 'bin = "$(1)"' -U -CP tag,bin | \ - sed 's/.*/- &/' - -list_commands = recsel -t $(basename $<) $< -e 'bin = "$(1)"' | \ - recfmt -f lists.fmt - -$(lists): lists/%.md: command.rec | lists/ - @printf '%s\n' '---' > $@ - @$(call get_title,$(basename $(notdir $@))) >> $@ - @printf '%s\n' 'tags: ' >> $@ - @$(call get_tags,$(basename $(notdir $@))) >> $@ - @printf '%s\n' '---' >> $@ - @$(call list_commands,$(basename $(notdir $@))) >> $@ - .PHONY: function function: ## Output a search function for .bashrc ${MAKE} --silent --touch query diff --git a/pub.mk b/pub.mk new file mode 100644 index 0000000..23171de --- /dev/null +++ b/pub.mk @@ -0,0 +1,42 @@ + +markdown = $(wildcard */*.md */*/*.md) + +publish = $(patsubst %, .publish/%, $(markdown)) + +.dbs/requires.fmt: | .dbs/ + echo "- [{{requires_title}}]({{requires_path}})" > $@ + +$(publish): .publish/%.md: %.md | .dbs/notes.rec .dbs/requires.fmt + mkdir -p $(@D) + sed -n '1,/^---$$/p' $< > $@ + test "$$(recsel -t guide -j requires .dbs/notes.rec -e "path = '$<'" -c)" -lt 1 \ + || { printf '\n---\n%s\n\n' "**Requirements**" >> $@ \ + && recsel -t guide -j requires .dbs/notes.rec -e "path = '$<'" -p requires_title,requires_path | recfmt -f .dbs/requires.fmt >> $@ \ + && printf '\n%s\n\n' '---' >> $@ ;} + sed '1,/---/d' $< >> $@ + +cmds != recsel command.rec -t command -G bin -CP bin | sort -u +lists = $(patsubst %,.publish/lists/%.md, $(cmds)) + +get_title = printf 'title: %s\n' '${1}' +get_tags = recsel -t $(basename $<) $< -G bin \ + -e 'bin = "$(1)"' -U -CP tag,bin | \ + sed 's/.*/- &/' + +list_commands = recsel -t $(basename $<) $< -e 'bin = "$(1)"' | \ + recfmt -f lists.fmt + +.publish/lists/:| .publish/ + +$(lists): .publish/lists/%.md: command.rec | .publish/lists/ + @printf '%s\n' '---' > $@ + @$(call get_title,$(basename $(notdir $@))) >> $@ + @printf '%s\n' 'tags: ' >> $@ + @$(call get_tags,$(basename $(notdir $@))) >> $@ + @printf '%s\n' '---' >> $@ + @$(call list_commands,$(basename $(notdir $@))) >> $@ + + +.PHONY: publish +publish: $(lists) $(publish) ## Web publishable web pages +