3 ## pinopress - the simple static blog generator
4 ## dependencies: sponge
7 SITEURL := https://blog.danieliu.xyz
13 .PHONY: help build clean
16 TEMPLATE_DIR := templates
21 ARTICLE_PATH := article
22 ARTICLE_LIST := $(basename $(shell ls $(SRC_DIR)))
24 # some helper functions
26 export SITEURL="$(SITEURL)"
27 export ARTICLE_PATH="$(ARTICLE_PATH)"
28 export USERGLOBAL1="$(USERGLOBAL1)"
29 export USERGLOBAL2="$(USERGLOBAL2)"
32 # usage: build_page [page_template] [item_template] [display_message]
36 cat $(TEMPLATE_DIR)/$(1) > "$@"
37 for article_file in `ls $(SRC_DIR)`; do
38 . ./$(MODULE_DIR)/md-header "$(SRC_DIR)/$$article_file"
39 envsubst < $(TEMPLATE_DIR)/$(2) | sed -i "/<!-- $(shell echo $(addprefix _mount_,$(basename $(basename $(2)))) | tr '[:lower:]' '[:upper:]') -->/r /dev/stdin" "$(@)"
41 $(call expand_mount,$@)
42 envsubst < "$@" | sponge "$@"
45 # usage: expand_mount [filename]
47 for mount in `sed -En 's/<!-- MOUNT_(.+) -->/\1/p' "$(1)"`; do
48 sed -i "/<!-- MOUNT_$$mount -->/r $(TEMPLATE_DIR)/`echo $$mount | tr '[:upper:]' '[:lower:]'`.template.html" "$(1)"
53 echo 'pinopress help|build|clean'
55 build: $(BUILD_DIR)/rolling.html $(BUILD_DIR)/archive.html $(BUILD_DIR)/feed.xml $(addprefix $(BUILD_DIR)/$(ARTICLE_PATH)/,$(addsuffix .html,$(ARTICLE_LIST)))
58 $(BUILD_DIR)/rolling.html:
59 $(call build_page,rollingpage.template.html,rollingitem.template.html,building rolling file)
62 $(BUILD_DIR)/archive.html:
63 $(call build_page,archivepage.template.html,archiveitem.template.html,building archive file)
66 $(BUILD_DIR)/feed.xml:
67 $(call build_page,feed.template.xml,feeditem.template.xml,building feed file)
70 $(BUILD_DIR)/$(ARTICLE_PATH)/%.html: $(SRC_DIR)/%.md
73 cat $(TEMPLATE_DIR)/articlepage.template.html > "$@"
74 # module pipeline starts here
75 ./$(MODULE_DIR)/md "$<" | sed -i "/<!-- _MOUNT_ARTICLECONTENT -->/r /dev/stdin" "$@"
76 . ./$(MODULE_DIR)/md-header "$<"
77 . ./$(MODULE_DIR)/readingtime "$<"
78 # module pipeline ends here
79 $(call expand_mount,$@)
80 envsubst < "$@" | sponge "$@"
84 rm $(BUILD_DIR)/rolling.html $(BUILD_DIR)/archive.html $(BUILD_DIR)/feed.xml $(BUILD_DIR)/$(ARTICLE_PATH)/*