From 60653dcdd81b6673fcc9aa4bf378c6730c399a51 Mon Sep 17 00:00:00 2001 From: ktyl Date: Sat, 16 Apr 2022 19:46:09 +0100 Subject: [PATCH] make html --- .gitignore | 1 + build/markdown2gemini.py | 0 build/markdown2html.py | 76 ++++++++++++++++++++++++++++++++++++++++ makefile | 27 ++++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 .gitignore create mode 100644 build/markdown2gemini.py create mode 100644 build/markdown2html.py create mode 100644 makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..89f9ac0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +out/ diff --git a/build/markdown2gemini.py b/build/markdown2gemini.py new file mode 100644 index 0000000..e69de29 diff --git a/build/markdown2html.py b/build/markdown2html.py new file mode 100644 index 0000000..2473fa1 --- /dev/null +++ b/build/markdown2html.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/makefile b/makefile new file mode 100644 index 0000000..72489e2 --- /dev/null +++ b/makefile @@ -0,0 +1,27 @@ +SRC_DIR = ./blogs +OUT_DIR = out/ +HTML_DIR = $(OUT_DIR)html +GEMINI_DIR = $(OUT_DIR)gemini + +MAKE_GEMINI = build/markdown2gemini.py +MAKE_HTML = build/markdown2html.py + +PAGES = $(shell find $(SRC_DIR) -wholename "$(BLOG_SRC_DIR)*.md") + +HTML_TARGETS = $(PAGES:$(SRC_DIR)/%.md=$(HTML_DIR)/%.html) +GEMINI_TARGETS = $(PAGES:$(SRC_DIR)/%.md=$(GEMINI_DIR)/%.gmi) + +_dummy := $(shell mkdir -p $(HTML_DIR) $(GEMINI_DIR)) + +$(HTML_DIR)/%.html: $(SRC_DIR)/%.md + python $(MAKE_HTML) $< $@ + +html: $(HTML_TARGETS) + echo $(HTML_TARGETS) + +gemini: + +all: html gemini + +clean: + rm -r $(OUT_DIR)