X-Git-Url: https://git.danieliu.xyz/?p=pinopress.git;a=blobdiff_plain;f=pinopress;h=5fe147cc5a8fbb2c29fc008de75b0dfd84af6002;hp=b47d785e49e20b4464cdf4e23d49f9ee343c5cb5;hb=HEAD;hpb=6ec6ed4c15ad3c37fbe1076aa33d26e9c21050a9 diff --git a/pinopress b/pinopress index b47d785..5fe147c 100755 --- a/pinopress +++ b/pinopress @@ -29,11 +29,23 @@ define export_common export USERGLOBAL2="$(USERGLOBAL2)" endef -# usage: loop_article [dest] [template_filename] -define loop_article +# 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" "$(1)" + envsubst < $(TEMPLATE_DIR)/$(2) | sed -i "//r /dev/stdin" "$(@)" + done + $(call expand_mount,$@) + envsubst < "$@" | sponge "$@" +endef + +# 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 @@ -44,40 +56,27 @@ build: $(BUILD_DIR)/rolling.html $(BUILD_DIR)/archive.html $(BUILD_DIR)/feed.xml .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 "$@" + $(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 > "$@" - $(call loop_article,"$@",archiveitem.template.html) - envsubst < "$@" | sponge "$@" + $(call build_page,archivepage.template.html,archiveitem.template.html,building archive file) .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 "$@" + $(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: