X-Git-Url: https://git.danieliu.xyz/?p=pinopress.git;a=blobdiff_plain;f=pinopress;h=5fe147cc5a8fbb2c29fc008de75b0dfd84af6002;hp=08b82cbd3fdd7157a2d6405db17cd66a253639a4;hb=HEAD;hpb=c2a180be93daf0ae77953d548c5bd658818452a3 diff --git a/pinopress b/pinopress index 08b82cb..5fe147c 100755 --- a/pinopress +++ b/pinopress @@ -5,8 +5,10 @@ # user variables SITEURL := https://blog.danieliu.xyz -USERVAR1 := -USERVAR2 := +USERGLOBAL1 := +USERGLOBAL2 := + +include config.mk .PHONY: help build clean @@ -22,54 +24,62 @@ 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: build_page [page_template] [item_template] [display_message] +define build_page + echo "$(3)" + $(export_common) + cat $(TEMPLATE_DIR)/$(1) > "$@" + 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" "$(@)" + done + $(call expand_mount,$@) + envsubst < "$@" | sponge "$@" endef -# usage: export_article [input md] -define export_article - export ARTICLE_TITLE=`./$(MODULE_DIR)/md-header "$(1)" name` - export PUBLISHED_DATE=`./$(MODULE_DIR)/md-header "$(1)" published` - # vvv this is sorta ugly vvv - export ARTICLE_URL="$(SITEURL)/$(ARTICLE_PATH)/$(subst .md,.html,$(notdir "$(1)"))" +# usage: expand_mount [filename] +define expand_mount + for mount in `sed -En 's//\1/p' "$(1)"`; do + sed -i "//r $(TEMPLATE_DIR)/`echo $$mount | tr '[:upper:]' '[:lower:]'`.template.html" "$(1)" + done endef help: echo 'pinopress help|build|clean' -build: $(BUILD_DIR)/rolling.html $(BUILD_DIR)/archive.html $(addprefix $(BUILD_DIR)/$(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 > "$@" - for article_file in `ls $(SRC_DIR)`; do - $(call export_article,"$(SRC_DIR)/$$article_file") - envsubst < $(TEMPLATE_DIR)/rollingitem.template.html | sed -i "//r /dev/stdin" "$@" - done - envsubst < "$@" | sponge "$@" + $(call build_page,rollingpage.template.html,rollingitem.template.html,building rolling file) .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 > "$@" - envsubst < "$@" | sponge "$@" + $(call build_page,archivepage.template.html,archiveitem.template.html,building archive file) + +.ONESHELL: +$(BUILD_DIR)/feed.xml: + $(call build_page,feed.template.xml,feeditem.template.xml,building feed file) .ONESHELL: $(BUILD_DIR)/$(ARTICLE_PATH)/%.html: $(SRC_DIR)/%.md echo "parsing $<" $(export_common) - $(call export_article,"$<") - cat $(TEMPLATE_DIR)/head.template.html > "$@" + cat $(TEMPLATE_DIR)/articlepage.template.html > "$@" # module pipeline starts here - ./$(MODULE_DIR)/md "$^" >> "$@" + ./$(MODULE_DIR)/md "$<" | sed -i "//r /dev/stdin" "$@" + . ./$(MODULE_DIR)/md-header "$<" + . ./$(MODULE_DIR)/readingtime "$<" # module pipeline ends here - cat $(TEMPLATE_DIR)/foot.template.html >> "$@" + $(call expand_mount,$@) envsubst < "$@" | sponge "$@" clean: echo 'cleaning...' - rm $(BUILD_DIR)/rolling.html $(BUILD_DIR)/archive.html $(BUILD_DIR)/$(ARTICLE_PATH)/* + rm $(BUILD_DIR)/rolling.html $(BUILD_DIR)/archive.html $(BUILD_DIR)/feed.xml $(BUILD_DIR)/$(ARTICLE_PATH)/*