|
| 1 | +SITE_HTTPS_URL := https://neotokyorebuild.github.io/ |
| 2 | +SITE_TITLE := Neotokyo; Rebuild |
| 3 | + |
| 4 | +SRC_DIR := src |
| 5 | +DST_DIR := _out |
| 6 | +SRCS := $(shell find $(SRC_DIR) -name '*.md') |
| 7 | +SRCS_CPY := $(SRC_DIR)/style.css |
| 8 | + |
| 9 | +BLOG_LIST_FILE := $(DST_DIR)/blog_list |
| 10 | +DSTS_HTML := $(SRCS:$(SRC_DIR)/%.md=$(DST_DIR)/%.html) |
| 11 | +DSTS_HTML_CPY := $(SRCS_CPY:$(SRC_DIR)/%=$(DST_DIR)/%) |
| 12 | + |
| 13 | +all: html |
| 14 | + |
| 15 | +clean: |
| 16 | + rm -fr $(DST_DIR) |
| 17 | + |
| 18 | +serve: |
| 19 | + python3 -m http.server -d $(DST_DIR) |
| 20 | + |
| 21 | +$(DST_DIR)/%.html: $(SRC_DIR)/%.md $(SRC_DIR)/_header.html $(SRC_DIR)/_footer.html |
| 22 | + @echo html: $@ |
| 23 | + @mkdir -p $(dir $@) |
| 24 | + @SSG_TITLE=$$(lowdown -X title $<); \ |
| 25 | + m4 -DSSG_TITLE="$$SSG_TITLE" $(SRC_DIR)/_header.html > $@.header.html.tmp |
| 26 | + @lowdown -Thtml -o $@.tmp $< |
| 27 | + @cat $@.header.html.tmp $@.tmp $(SRC_DIR)/_footer.html > $@ |
| 28 | + @rm $@.tmp $@.header.html.tmp |
| 29 | + @case $< in $(SRC_DIR)/blog/*) \ |
| 30 | + entry_date=$$(dir $< | cut -d'/' -f3); \ |
| 31 | + echo "$$entry_date $$(lowdown -X title $<)" >> $(BLOG_LIST_FILE);; \ |
| 32 | + esac |
| 33 | + |
| 34 | +$(DST_DIR)/%: $(SRC_DIR)/% |
| 35 | + @echo "html (copy):" $@ |
| 36 | + @mkdir -p $(dir $@) |
| 37 | + @cp $< $@ |
| 38 | + |
| 39 | +$(DST_DIR)/blog/index.html: $(SRC_DIR)/blog/*/*.md $(SRC_DIR)/_header.html $(SRC_DIR)/_footer.html |
| 40 | + @echo "html (blog):" $@ |
| 41 | + @echo "<h1>Blog</h1><ul>" > $@.mid |
| 42 | + @mv $(BLOG_LIST_FILE) $(BLOG_LIST_FILE).tmp |
| 43 | + @cat $(BLOG_LIST_FILE).tmp | sort -ur > $(BLOG_LIST_FILE) |
| 44 | + @rm $(BLOG_LIST_FILE).tmp |
| 45 | + @cat $(BLOG_LIST_FILE) | while read line; do \ |
| 46 | + entry_date=$$(echo "$$line" | cut -f1); \ |
| 47 | + title=$$(echo "$$line" | cut -f2); \ |
| 48 | + echo "<li><a href=\"$$entry_date\">$$entry_date - $$title</a></li>"; \ |
| 49 | + done >> $@.mid |
| 50 | + @echo "</ul>" >> $@.mid |
| 51 | + @m4 -DSSG_TITLE="Blog" $(SRC_DIR)/_header.html > $@.header |
| 52 | + @cat $@.header $@.mid $(SRC_DIR)/_footer.html > $@ |
| 53 | + @rm $@.header $@.mid |
| 54 | + |
| 55 | +$(DST_DIR)/blog/atom.xml: $(SRC_DIR)/blog/*/*.md |
| 56 | + @echo "html (atom):" $@ |
| 57 | + @echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>" > $@ |
| 58 | + @echo "<feed xmlns=\"http://www.w3.org/2005/Atom\">" >> $@ |
| 59 | + @echo "<title type=\"text\">$(SITE_TITLE)</title>" >> $@ |
| 60 | + @echo "<updated>$$(head -n1 "$(BLOG_LIST_FILE)" | cut -f1)T00:00:00Z</updated>" >> $@ |
| 61 | + @echo "<id>$(SITE_HTTPS_URL)blog/</id>" >> $@ |
| 62 | + @echo "<author><name>$(SITE_TITLE)</name></author>" >> $@ |
| 63 | + @echo "<link rel=\"alternate\" type=\"text/html\" href=\"$(SITE_HTTPS_URL)blog/\"/>" >> $@ |
| 64 | + @echo "<link rel=\"self\" type=\"application/atom+xml\" href=\"$(SITE_HTTPS_URL)blog/atom.xml\"/>" >> $@ |
| 65 | + @cat $(BLOG_LIST_FILE) | while read line; do \ |
| 66 | + entry_date=$$(echo "$$line" | cut -f1); \ |
| 67 | + title=$$(echo "$$line" | cut -f2); \ |
| 68 | + entry_url=$$(echo "$(SITE_HTTPS_URL)blog/$$entry_date/"); \ |
| 69 | + echo "<entry>"; \ |
| 70 | + echo "<title>$$title</title>"; \ |
| 71 | + echo "<link rel=\"alternate\" type=\"text/html\" href=\"$$entry_url\"/>"; \ |
| 72 | + echo "<updated>$${entry_date}T00:00:00Z</updated>"; \ |
| 73 | + echo "<published>$${entry_date}T00:00:00Z</published>"; \ |
| 74 | + echo "<summary>$$(lowdown -X summary $(SRC_DIR)/blog/$${entry_date}/index.md)</summary>"; \ |
| 75 | + echo "<id>$$entry_url</id>"; \ |
| 76 | + echo "</entry>"; \ |
| 77 | + done >> $@ |
| 78 | + @echo "</feed>" >> $@ |
| 79 | + |
| 80 | +html: $(DSTS_HTML) $(DSTS_HTML_CPY) #$(DST_DIR)/blog/index.html $(DST_DIR)/blog/atom.xml |
| 81 | + |
| 82 | +.PHONY: all clean html |
| 83 | + |
0 commit comments