microblog.pub/scripts/generate_docs.py

32 lines
771 B
Python
Raw Normal View History

2022-07-04 17:02:06 +00:00
from pathlib import Path
from jinja2 import Environment
from jinja2 import FileSystemLoader
from jinja2 import select_autoescape
from markdown import markdown
2022-07-04 20:00:19 +00:00
from app.config import VERSION
2022-07-04 17:02:06 +00:00
def markdownify(content: str) -> str:
return markdown(content, extensions=["mdx_linkify"])
def main() -> None:
# Setup Jinja
loader = FileSystemLoader("docs/templates")
env = Environment(loader=loader, autoescape=select_autoescape())
template = env.get_template("layout.html")
Path("docs/dist").mkdir(exist_ok=True)
readme = Path("README.md")
template.stream(
2022-07-04 20:00:19 +00:00
content=markdownify(readme.read_text().removeprefix("# microblog.pub")),
version=VERSION,
2022-07-04 17:02:06 +00:00
).dump("docs/dist/index.html")
if __name__ == "__main__":
main()