From 89bdaf95b9e708dd008f19db1722788a0ba24f88 Mon Sep 17 00:00:00 2001 From: ktyl Date: Sat, 18 Nov 2023 00:32:49 +0000 Subject: [PATCH] feat(garden): generate html files --- src/garden/.gitignore | 1 + src/garden/Makefile | 11 ++++++++--- src/garden/md2html.py | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 src/garden/.gitignore create mode 100644 src/garden/md2html.py diff --git a/src/garden/.gitignore b/src/garden/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/src/garden/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/src/garden/Makefile b/src/garden/Makefile index b77f908..1f28d56 100644 --- a/src/garden/Makefile +++ b/src/garden/Makefile @@ -1,10 +1,15 @@ -html: feed.py Makefile +py = feed.py books.py +md = rss.md book-collecting.md gardens.md +html = $(md:%.md=%.html) + +site: Makefile $(md) $(py) mkdir html - cp feed.py Makefile html - cp *.md html + python md2html.py $(md) + cp $(html) $(py) Makefile html clean-html: [[ -d html ]] && rm -r html + rm $(pages_html) .PHONY: clean-html diff --git a/src/garden/md2html.py b/src/garden/md2html.py new file mode 100644 index 0000000..40b1610 --- /dev/null +++ b/src/garden/md2html.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +import sys +import markdown + +def print_usage(): + print(f"usage: python {sys.argv[0]} PATHS") + print("") + print("\t\PATHS\tpaths of input markdown files") + +if len(sys.argv) < 2: + print_usage() + sys.exit(1) + +paths = sys.argv[1:] + +bad_paths = [p for p in paths if not p.endswith(".md")] +if len(bad_paths) != 0: + for p in bad_paths: + print(f"Not a markdown file: {p}") + + exit(1) + +def write_html(src : str): + with open(src) as md: + dest = src.replace(".md", ".html") + with open(dest, "w") as html: + print(f"{src} -> {dest}") + html.write(markdown.markdown(md.read())) + +for p in paths: + write_html(p)