feat(garden): generate html files

This commit is contained in:
ktyl 2023-11-18 00:32:49 +00:00
parent 2d0fb9ed84
commit 89bdaf95b9
3 changed files with 41 additions and 3 deletions

1
src/garden/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.html

View File

@ -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 mkdir html
cp feed.py Makefile html python md2html.py $(md)
cp *.md html cp $(html) $(py) Makefile html
clean-html: clean-html:
[[ -d html ]] && rm -r html [[ -d html ]] && rm -r html
rm $(pages_html)
.PHONY: clean-html .PHONY: clean-html

32
src/garden/md2html.py Normal file
View File

@ -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)