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)