X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=pinopress;h=34695863d38092d171eb2893c59ce5f3297c75bb;hb=00a2c5274946042785d6425a61281efa07da7e48;hp=c31657cd91809cc386de1d4ab18325659d612c09;hpb=65d70f73b4e67c4c5768a15bb85d1dcfb1a66351;p=pinopress.git diff --git a/pinopress b/pinopress index c31657c..3469586 100755 --- a/pinopress +++ b/pinopress @@ -1,6 +1,12 @@ #!/usr/bin/make -sf +## pinopress - the simple static blog generator +## dependencies: sponge + +# user variables SITEURL := https://blog.danieliu.xyz +USERGLOBAL1 := +USERGLOBAL2 := .PHONY: help build clean @@ -10,33 +16,67 @@ BUILD_DIR := build SRC_DIR := articles MODULE_DIR := modules -ARTICLE_PATH := $(BUILD_DIR)/article - +ARTICLE_PATH := article ARTICLE_LIST := $(basename $(shell ls $(SRC_DIR))) +# some helper functions +define export_common + export SITEURL="$(SITEURL)" + export ARTICLE_PATH="$(ARTICLE_PATH)" + export USERGLOBAL1="$(USERGLOBAL1)" + export USERGLOBAL2="$(USERGLOBAL2)" +endef + +# usage: loop_article [dest] [template_filename] +define loop_article + for article_file in `ls $(SRC_DIR)`; do + . ./$(MODULE_DIR)/md-header "$(SRC_DIR)/$$article_file" + envsubst < $(TEMPLATE_DIR)/$(2) | sed -i "//r /dev/stdin" "$(1)" + done +endef + help: echo 'pinopress help|build|clean' -build: $(BUILD_DIR)/rolling.html $(BUILD_DIR)/archive.html $(ARTICLE_PATH)/$(addsuffix .html,$(ARTICLE_LIST)) - echo 'building...' +build: $(BUILD_DIR)/rolling.html $(BUILD_DIR)/archive.html $(BUILD_DIR)/feed.xml $(addprefix $(BUILD_DIR)/$(ARTICLE_PATH)/,$(addsuffix .html,$(ARTICLE_LIST))) +.ONESHELL: $(BUILD_DIR)/rolling.html: echo 'building rolling file' + $(export_common) cat $(TEMPLATE_DIR)/head.template.html $(TEMPLATE_DIR)/rollingbody.template.html $(TEMPLATE_DIR)/foot.template.html > "$@" + $(call loop_article,"$@",rollingitem.template.html) + envsubst < "$@" | sponge "$@" +.ONESHELL: $(BUILD_DIR)/archive.html: echo 'building archive file' + $(export_common) cat $(TEMPLATE_DIR)/head.template.html $(TEMPLATE_DIR)/archivebody.template.html $(TEMPLATE_DIR)/foot.template.html > "$@" + $(call loop_article,"$@",archiveitem.template.html) + envsubst < "$@" | sponge "$@" + +.ONESHELL: +$(BUILD_DIR)/feed.xml: + echo 'building feed file' + $(export_common) + cat $(TEMPLATE_DIR)/feed.template.xml > "$@" + $(call loop_article,"$@",feeditem.template.xml) + envsubst < "$@" | sponge "$@" -$(ARTICLE_PATH)/%.html: articles/%.md - echo 'parsing $^' +.ONESHELL: +$(BUILD_DIR)/$(ARTICLE_PATH)/%.html: $(SRC_DIR)/%.md + echo "parsing $<" + $(export_common) + $(call export_article,"$<") cat $(TEMPLATE_DIR)/head.template.html > "$@" # module pipeline starts here ./$(MODULE_DIR)/md "$^" >> "$@" # module pipeline ends here cat $(TEMPLATE_DIR)/foot.template.html >> "$@" + envsubst < "$@" | sponge "$@" clean: echo 'cleaning...' - rm $(BUILD_DIR)/rolling.html $(BUILD_DIR)/archive.html $(ARTICLE_PATH)/* + rm $(BUILD_DIR)/rolling.html $(BUILD_DIR)/archive.html $(BUILD_DIR)/feed.xml $(BUILD_DIR)/$(ARTICLE_PATH)/*