diff --git a/makefile b/makefile index 7bcedf7..1c1fbb3 100644 --- a/makefile +++ b/makefile @@ -24,6 +24,7 @@ HTML_INCLUDES = $(shell find $(SRC_DIR)/inc_html -name *.html) CSS_INCLUDES = $(shell find $(SRC_DIR)/inc_css -name *.css) BLOG_INDEX = $(OUT_DIR)/blog.html +BLOG_RSS = $(BLOG_OUT_DIR)/index.xml BLOG_INDEX_LINKS = $(BLOG_TMP_DIR)/blogindexlinks.html BLOG_TARGETS = $(BLOG_PAGES:$(BLOG_SRC_DIR)/%.md=$(BLOG_OUT_DIR)/%.html) @@ -45,9 +46,16 @@ deploy: site $(OUT_DIR)/%.html: $(ROOT_DIR)/%.html $(HTML_INCLUDES) $(BLOG_INDEX_LINKS) | $(OUT_DIR) python ppp/ppp.py $< $(HTML_INCLUDES) $(BLOG_INDEX_LINKS) > $@ -blog: $(BLOG_TARGETS) | $(BLOG_TMP_DIR) +$(OUT_DIR)/%.css: $(ROOT_DIR)/%.css $(CSS_INCLUDES) | $(OUT_DIR) + python ppp/ppp.py $< $(CSS_INCLUDES) > $@ -blog-index: $(BLOG_INDEX) +$(OUT_DIR): + mkdir -p $@ + +blog: $(BLOG_TARGETS) $(BLOG_RSS) | $(BLOG_TMP_DIR) + +$(BLOG_RSS): $(BLOG_PAGES) + python scripts/mkblogrss.py $(BLOG_PAGES) > $@ $(BLOG_INDEX_LINKS): $(BLOG_TARGETS) | $(BLOG_TMP_DIR) python scripts/mkblogindex.py $(BLOG_TARGETS) > $@ @@ -66,14 +74,6 @@ $(BLOG_OUT_DIR): | $(OUT_DIR) $(BLOG_TMP_DIR): mkdir -p $@ -$(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) > $@ - -$(OUT_DIR): - mkdir -p $@ clean: rm -rf $(OUT_DIR) $(BLOG_TMP_DIR) diff --git a/scripts/mkblogindex.py b/scripts/mkblogindex.py index 7db00bd..516a586 100644 --- a/scripts/mkblogindex.py +++ b/scripts/mkblogindex.py @@ -28,7 +28,12 @@ posts.reverse() # for each file we want to output an tag with a relative href to the site root for path in posts: - date = re.sub(path_pattern, r'\2-\3-\4', path) + m = re.match(path_pattern, path) + year = m.group(2) + month = m.group(3).rjust(2, '0') + day = m.group(4).rjust(2, '0') + + date = f'{year}-{month}-{day}' title = "" with open(path) as f: diff --git a/scripts/mkblogrss.py b/scripts/mkblogrss.py new file mode 100644 index 0000000..dd1d862 --- /dev/null +++ b/scripts/mkblogrss.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 + +import markdown +import pathlib +import sys +import re + +def print_usage(): + print("\nusage: python mkblogrss.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:] + +# header and footer to enclose feed items +header = """ + + + Just Testing + https://ktyl.dev/blog/index.html + Vaguely technical "blogging" from Cat + + """ +footer = "" + +# regex patterns +title_pattern = re.compile("

(.+)

") +path_pattern = re.compile("(.+)\/(\d{4})\/(\d{1,2})\/(\d{1,2})\/(.+).md") + +def make_item(path): + str = "\n" + + # get the HTML version of the file + text = "" + with open(path) as f: + text = f.read() + html = markdown.markdown(text, extensions=["fenced_code"]) + + # title + title = "" + m = title_pattern.match(html) + title = m.group(1) + str += f"{title}\n" + + # link + url = "/".join(pathlib.Path(path).parts[2:]) + url = url.replace(".md", ".html") + link = f"https://ktyl.dev/blog/{url}" + str += f"{link}\n" + + # content + description = html + description = re.sub('<', '<', description) + description = re.sub('>', '>', description) + str += f"{description}\n" + + # pub date + date = re.sub(path_pattern, r'\2-\3-\4', path) + str += f"{date}\n" + + str += "" + + return str + +# print everything! +print(header) +for p in posts: + print(make_item(p)) +print(footer) + diff --git a/src/inc_html/socials.html b/src/inc_html/socials.html index 616d652..194e364 100644 --- a/src/inc_html/socials.html +++ b/src/inc_html/socials.html @@ -1,7 +1,7 @@
+ + - -