3 ## pinopress - the simple static blog generator
4 ## dependencies: sponge
7 SITEURL := https://blog.danieliu.xyz
11 .PHONY: help build clean
14 TEMPLATE_DIR := templates
19 ARTICLE_PATH := article
20 ARTICLE_LIST := $(basename $(shell ls $(SRC_DIR)))
22 # some helper functions
24 export SITEURL="$(SITEURL)"
25 export USERGLOBAL1="$(USERGLOBAL1)"
26 export USERGLOBAL2="$(USERGLOBAL2)"
29 # usage: export_article [input md]
31 export ARTICLE_TITLE=`./$(MODULE_DIR)/md-header "$(1)" name`
32 export PUBLISHED_DATE=`./$(MODULE_DIR)/md-header "$(1)" published`
33 export DESCRIPTION=`./$(MODULE_DIR)/md-header "$(1)" description`
34 export USERLOCAL1=`./$(MODULE_DIR)/md-header "$(1)" userlocal1`
35 export USERLOCAL2=`./$(MODULE_DIR)/md-header "$(1)" userlocal2`
36 # vvv this is sorta ugly vvv
37 export ARTICLE_URL="$(SITEURL)/$(ARTICLE_PATH)/$(subst .md,.html,$(notdir "$(1)"))"
40 # usage: loop_article [dest] [template_filename]
42 for article_file in `ls $(SRC_DIR)`; do
43 $(call export_article,"$(SRC_DIR)/$$article_file")
44 envsubst < $(TEMPLATE_DIR)/$(2) | sed -i "/<!-- $(shell echo $(addprefix mount_,$(basename $(basename $(2)))) | tr '[:lower:]' '[:upper:]') -->/r /dev/stdin" "$(1)"
49 echo 'pinopress help|build|clean'
51 build: $(BUILD_DIR)/rolling.html $(BUILD_DIR)/archive.html $(BUILD_DIR)/feed.xml $(addprefix $(BUILD_DIR)/$(ARTICLE_PATH)/,$(addsuffix .html,$(ARTICLE_LIST)))
54 $(BUILD_DIR)/rolling.html:
55 echo 'building rolling file'
57 cat $(TEMPLATE_DIR)/head.template.html $(TEMPLATE_DIR)/rollingbody.template.html $(TEMPLATE_DIR)/foot.template.html > "$@"
58 $(call loop_article,"$@",rollingitem.template.html)
59 envsubst < "$@" | sponge "$@"
62 $(BUILD_DIR)/archive.html:
63 echo 'building archive file'
65 cat $(TEMPLATE_DIR)/head.template.html $(TEMPLATE_DIR)/archivebody.template.html $(TEMPLATE_DIR)/foot.template.html > "$@"
66 $(call loop_article,"$@",archiveitem.template.html)
67 envsubst < "$@" | sponge "$@"
70 $(BUILD_DIR)/feed.xml:
71 echo 'building feed file'
73 cat $(TEMPLATE_DIR)/feed.template.xml > "$@"
74 $(call loop_article,"$@",feeditem.template.xml)
75 envsubst < "$@" | sponge "$@"
78 $(BUILD_DIR)/$(ARTICLE_PATH)/%.html: $(SRC_DIR)/%.md
81 $(call export_article,"$<")
82 cat $(TEMPLATE_DIR)/head.template.html > "$@"
83 # module pipeline starts here
84 ./$(MODULE_DIR)/md "$^" >> "$@"
85 # module pipeline ends here
86 cat $(TEMPLATE_DIR)/foot.template.html >> "$@"
87 envsubst < "$@" | sponge "$@"
91 rm $(BUILD_DIR)/rolling.html $(BUILD_DIR)/archive.html $(BUILD_DIR)/feed.xml $(BUILD_DIR)/$(ARTICLE_PATH)/*