X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=pinopress;h=08b82cbd3fdd7157a2d6405db17cd66a253639a4;hb=c2a180be93daf0ae77953d548c5bd658818452a3;hp=d056dabf31d4c9446b462ff925e2f778846813ae;hpb=03c62b630fd92a5b32920be4ee33453a3c8e8b3c;p=pinopress.git diff --git a/pinopress b/pinopress index d056dab..08b82cb 100755 --- a/pinopress +++ b/pinopress @@ -1,21 +1,75 @@ -#!/usr/bin/make -f +#!/usr/bin/make -sf +## pinopress - the simple static blog generator +## dependencies: sponge + +# user variables SITEURL := https://blog.danieliu.xyz +USERVAR1 := +USERVAR2 := .PHONY: help build clean # internal variables TEMPLATE_DIR := templates BUILD_DIR := build -ARTICLE_DIR := articles +SRC_DIR := articles +MODULE_DIR := modules + +ARTICLE_PATH := article +ARTICLE_LIST := $(basename $(shell ls $(SRC_DIR))) -ARTICLE_LIST := $(basename $(shell ls $(ARTICLE_DIR))) +# some helper functions +define export_common + export SITEURL="$(SITEURL)" + export USERVAR1="$(USERVAR1)" + export USERVAR2="$(USERVAR2)" +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)"))" +endef help: - @echo 'pinopress help|build|clean' + echo 'pinopress help|build|clean' + +build: $(BUILD_DIR)/rolling.html $(BUILD_DIR)/archive.html $(addprefix $(BUILD_DIR)/$(ARTICLE_PATH)/,$(addsuffix .html,$(ARTICLE_LIST))) -build: - @echo 'building...' +.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 "$@" + +.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 "$@" + +.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...' + echo 'cleaning...' + rm $(BUILD_DIR)/rolling.html $(BUILD_DIR)/archive.html $(BUILD_DIR)/$(ARTICLE_PATH)/* +