diff --git a/makefile b/makefile index 0a651c4..dbd8459 100644 --- a/makefile +++ b/makefile @@ -19,7 +19,10 @@ IMAGES = $(shell find $(IMG_DIR) -wholename "$(IMG_DIR)/*.png") HTML_INCLUDES = $(shell find $(SRC_DIR)/inc_html -name *.html) CSS_INCLUDES = $(shell find $(SRC_DIR)/inc_css -name *.css) -BLOG_TARGETS = $(BLOG_PAGES:$(BLOG_SRC_DIR)/%.md=$(BLOG_OUT_DIR)/%.html) +BLOG_INDEX = $(OUT_DIR)/blog.html +BLOG_INDEX_LINKS = $(BLOG_TMP_DIR)/blogindexlinks.html +BLOG_TARGETS = $(BLOG_PAGES:$(BLOG_SRC_DIR)/%.md=$(BLOG_OUT_DIR)/%.html) + HTML_TARGETS = $(PAGES:$(ROOT_DIR)/%.html=$(OUT_DIR)/%.html) CSS_TARGETS = $(STYLES:$(ROOT_DIR)/%.css=$(OUT_DIR)/%.css) PNG_TARGETS = $(IMG_DIR)/%.png=$(OUT_DIR)/%.png @@ -29,6 +32,11 @@ run: $(HTML_TARGETS) $(CSS_TARGETS) blog | $(OUT_DIR) blog: $(BLOG_TARGETS) | $(BLOG_TMP_DIR) +blog-index: $(BLOG_INDEX) + +$(BLOG_INDEX_LINKS): $(BLOG_TARGETS) | $(BLOG_TMP_DIR) + python scripts/mkblogindex.py $(BLOG_TARGETS) > $@ + $(BLOG_OUT_DIR)/%.html: $(BLOG_OUT_DIR)/%.html.tmp $(HTML_INCLUDES) $(CSS_TARGETS) python ppp/ppp.py $< $(HTML_INCLUDES) > $@ cp $(CSS_TARGETS) `dirname $@` @@ -43,8 +51,8 @@ $(BLOG_OUT_DIR): | $(OUT_DIR) $(BLOG_TMP_DIR): mkdir -p $@ -$(OUT_DIR)/%.html: $(ROOT_DIR)/%.html $(HTML_INCLUDES) | $(OUT_DIR) - python ppp/ppp.py $< $(HTML_INCLUDES) > $@ +$(OUT_DIR)/%.html: $(ROOT_DIR)/%.html $(HTML_INCLUDES) $(BLOG_INDEX_LINKS) | $(OUT_DIR) + python ppp/ppp.py $< $(HTML_INCLUDES) $(BLOG_INDEX_LINKS) > $@ $(OUT_DIR)/%.css: $(ROOT_DIR)/%.css $(CSS_INCLUDES) | $(OUT_DIR) python ppp/ppp.py $< $(CSS_INCLUDES) > $@ @@ -52,5 +60,5 @@ $(OUT_DIR)/%.css: $(ROOT_DIR)/%.css $(CSS_INCLUDES) | $(OUT_DIR) $(OUT_DIR): mkdir -p $@ -clean: - rm -r $(OUT_DIR) +clean: + rm -rf $(OUT_DIR) $(BLOG_TMP_DIR) diff --git a/scripts/mkblog.py b/scripts/mkblog.py index 43e6a88..aed2d65 100644 --- a/scripts/mkblog.py +++ b/scripts/mkblog.py @@ -19,7 +19,7 @@ import re def print_usage(): print("\nusage: python mkblog.py SRC DEST\n") print("\n") - print("\t\SRC\tinput markdown file") + print("\t\tSRC\tinput markdown file") print("\t\tDEST\tdestination html file") # check args diff --git a/scripts/mkblogindex.py b/scripts/mkblogindex.py new file mode 100644 index 0000000..2f79b58 --- /dev/null +++ b/scripts/mkblogindex.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 + +import sys +import re + +# we expect the arguments to be filepaths to each blog post + +def print_usage(): + print("\nusage: python mkblogindex.py POSTS\n") + print("\n") + print("\t\tPOSTS\tfilepaths of blog posts") + +# check args for at least one file path +if len(sys.argv) < 2: + print_usage() + sys.exit(1) + +# posts are arguments from index 1 onwards +posts = sys.argv[1:] + +dir_pattern = re.compile("(.+)/(blog\/.+\.html)") +path_pattern = re.compile("(.+)\/(\d{4})\/(\d{1,2})\/(\d{1,2})\/(.+).html") +title_pattern = re.compile("