diff --git a/blog b/blog index 9624dd1..90d9f30 160000 --- a/blog +++ b/blog @@ -1 +1 @@ -Subproject commit 9624dd16001391ce33e982caeefd81e02cee1a42 +Subproject commit 90d9f3060491a13a9b41c39fbd5d99f1eabc2444 diff --git a/makefile b/makefile index dca2fae..0a2d66c 100644 --- a/makefile +++ b/makefile @@ -4,8 +4,13 @@ OUT_DIR = site ROOT_DIR = $(SRC_DIR)/root +BLOG_SRC_DIR = blog/blogs +BLOG_OUT_DIR = $(OUT_DIR)/blog +BLOG_TMP_DIR = .blogtmp + PAGES = $(shell find $(ROOT_DIR) -wholename "$(ROOT_DIR)*.html") STYLES = $(shell find $(ROOT_DIR) -wholename "$(ROOT_DIR)*.css") +BLOG_PAGES = $(shell find $(BLOG_SRC_DIR) -wholename "$(BLOG_SRC_DIR)*.md") IMAGES = $(shell find $(IMG_DIR) -wholename "$(IMG_DIR)/*.png") #IMAGES = $(IMAGES:$(shell find $(IMG_DIR) -wholename "$(IMG_DIR)/*.jpg")) @@ -14,20 +19,33 @@ 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) 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 -run: $(HTML_TARGETS) $(CSS_TARGETS) +run: $(HTML_TARGETS) $(CSS_TARGETS) blog | $(OUT_DIR) cp $(IMG_DIR)/*.png $(OUT_DIR)/ -$(OUT_DIR)/%.html: $(ROOT_DIR)/%.html $(HTML_INCLUDES) - mkdir -p $(OUT_DIR) +blog: $(BLOG_TARGETS) | $(BLOG_TMP_DIR) + +$(BLOG_OUT_DIR)/%.html: $(BLOG_SRC_DIR)/%.md | $(BLOG_OUT_DIR) + python scripts/mkblog.py $< $@ + +$(BLOG_OUT_DIR): | $(OUT_DIR) + mkdir -p $@ + +$(BLOG_TMP_DIR): + mkdir -p $@ + +$(OUT_DIR)/%.html: $(ROOT_DIR)/%.html $(HTML_INCLUDES) | $(OUT_DIR) python ppp/ppp.py $< $(HTML_INCLUDES) > $@ -$(OUT_DIR)/%.css: $(ROOT_DIR)/%.css $(CSS_INCLUDES) - mkdir -p $(OUT_DIR) +$(OUT_DIR)/%.css: $(ROOT_DIR)/%.css $(CSS_INCLUDES) | $(OUT_DIR) python ppp/ppp.py $< $(CSS_INCLUDES) > $@ +$(OUT_DIR): + mkdir -p $@ + clean: rm -r $(OUT_DIR) diff --git a/scripts/mkblog.py b/scripts/mkblog.py new file mode 100644 index 0000000..2473fa1 --- /dev/null +++ b/scripts/mkblog.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python + +import os +import sys +import markdown + +# SRC +# +-2022/ +# | +-10/ +# | +-12/ +# | +-25/ +# +-2023/ +# | +-1/ +# | +-26/ +# | +-3/ +# ... + +def print_usage(): + print("\nusage: python mkblog.py SRC DEST\n") + print("\n") + print("\t\SRC\tinput markdown file") + print("\t\tDEST\tdestination html file") + +# check args +if len(sys.argv) != 3: + print_usage() + sys.exit(1) + +src_file = sys.argv[1] +dest_file = sys.argv[2] + +# check blog root exists +if not os.path.isfile(src_file): + print("{blog_root} doesn't exist") + sys.exit(1) + +# make dest dir if it doesnt exist + +with open(src_file) as md: + + dest_dir = os.path.dirname(dest_file) + print(dest_dir) + if not os.path.isdir(dest_dir): + os.makedirs(dest_dir) + + with open(dest_file, "w") as html: + + print(f"{src_file} -> {dest_file}") + html.write(markdown.markdown(md.read())) + +#for dir_y in os.listdir(src_dir): +# path_y = os.path.join(src_dir, dir_y) +# +# if not os.path.isdir(path_y): +# continue +# +# for dir_m in os.listdir(path_y): +# path_m = os.path.join(path_y, dir_m) +# +# if not os.path.isdir(path_m): +# continue +# +# for dir_d in os.listdir(path_m): +# path_d = os.path.join(path_m, dir_d) +# +# if not os.path.isdir(path_d): +# continue +# +# print(path_d) +# for md in os.listdir(path_d): +# path_md = os.path.join(path_d, md) +# +# if not os.path.isfile(path_md): +# continue + + diff --git a/todo.md b/todo.md index e77e754..9bb0661 100644 --- a/todo.md +++ b/todo.md @@ -26,7 +26,14 @@ * [-] features * [-] blog - * [x] parse markdown blog into html + * [ ] blog builder + * [ ] i want to generate an entire page based on the existence of one markdown file + * [ ] the file should contain no metadata, that should all be generated automatically + * [ ] yyyy/mm/dd folder structure - can probably be copied from source + * [ ] auto generated