X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=pinopress;h=3623b2f65d0921eacf2586a169bb608c8434633b;hb=394bc43d24de087865fa4eed1920411c1a6d7ebd;hp=5157f99c91fea441927b88e021d5e14f3398913c;hpb=d9e98960c517be5806c756518f46827cf59d0471;p=pinopress.git diff --git a/pinopress b/pinopress index 5157f99..3623b2f 100755 --- a/pinopress +++ b/pinopress @@ -1,8 +1,12 @@ #!/usr/bin/make -sf +## pinopress - the simple static blog generator +## dependencies: sponge + +# user variables SITEURL := https://blog.danieliu.xyz -USERVAR1 := -USERVAR2 := +USERGLOBAL1 := +USERGLOBAL2 := .PHONY: help build clean @@ -12,26 +16,36 @@ 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 USERVAR1="$(USERVAR1)" - export USERVAR2="$(USERVAR2)" + 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)) +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: @@ -39,14 +53,23 @@ $(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 "$@" .ONESHELL: -$(ARTICLE_PATH)/%.html: articles/%.md - echo 'parsing $^' +$(BUILD_DIR)/$(ARTICLE_PATH)/%.html: $(SRC_DIR)/%.md + echo "parsing $<" $(export_common) - export ARTICLE_TITLE="$(shell ./$(MODULE_DIR)/md-header "$<" name)" - export PUBLISHED_DATE="$(shell ./$(MODULE_DIR)/md-header "$<" published)" + $(call export_article,"$<") + . ./$(MODULE_DIR)/md-header "$<" cat $(TEMPLATE_DIR)/head.template.html > "$@" # module pipeline starts here ./$(MODULE_DIR)/md "$^" >> "$@" @@ -56,5 +79,5 @@ $(ARTICLE_PATH)/%.html: articles/%.md 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)/*