Sources of one history of Larlet’s family: https://larlet.fr/famille/histoire/ https://larlet.fr/famille/histoire/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

famille.py 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python3
  2. import codecs
  3. import os
  4. from pathlib import Path
  5. from time import perf_counter
  6. import markdown
  7. from jinja2 import Environment as Env
  8. from jinja2 import FileSystemLoader
  9. from minicli import cli, run, wrap
  10. HERE = Path(".")
  11. FAMILLE = HERE / "famille"
  12. environment = Env(loader=FileSystemLoader(str(FAMILLE / "templates")))
  13. def parse_markdown(file_path):
  14. """Extract content including footnotes from a markdown file."""
  15. parser = markdown.Markdown(extensions=["footnotes"])
  16. with codecs.open(file_path, "r") as source:
  17. return parser.convert(source.read())
  18. def collection():
  19. """Retrieve famille's chapters from markdown files."""
  20. SRC_PATH = FAMILLE / "sources"
  21. for chapter in sorted(os.listdir(SRC_PATH)):
  22. if chapter.endswith(".md"):
  23. content = parse_markdown(SRC_PATH / chapter)
  24. yield (
  25. """<article id="{id}">
  26. {content}
  27. </article>""".format(
  28. id=chapter[:-3], content=content.replace("'", "’")
  29. )
  30. )
  31. @cli
  32. def generate():
  33. template = environment.get_template("histoire.html")
  34. page = template.render(chapters=collection())
  35. open(FAMILLE / "histoire" / "index.html", "w").write(page)
  36. @wrap
  37. def perf_wrapper():
  38. start = perf_counter()
  39. yield
  40. elapsed = perf_counter() - start
  41. print(f"Done in {elapsed:.5f} seconds.")
  42. if __name__ == "__main__":
  43. run()