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.7KB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. import minicli
  8. from jinja2 import Environment as Env
  9. from jinja2 import FileSystemLoader
  10. from usine import connect, run
  11. HERE = Path(".")
  12. FAMILLE = HERE / "famille"
  13. environment = Env(loader=FileSystemLoader(str(FAMILLE / "templates")))
  14. def parse_markdown(file_path):
  15. """Extract content including footnotes from a markdown file."""
  16. parser = markdown.Markdown(extensions=["footnotes"])
  17. with codecs.open(file_path, "r") as source:
  18. return parser.convert(source.read())
  19. def collection():
  20. """Retrieve famille's chapters from markdown files."""
  21. SRC_PATH = FAMILLE / "sources"
  22. for chapter in sorted(os.listdir(SRC_PATH)):
  23. if chapter.endswith(".md"):
  24. content = parse_markdown(SRC_PATH / chapter)
  25. yield (
  26. """<article id="{id}">
  27. {content}
  28. </article>""".format(
  29. id=chapter[:-3], content=content.replace("'", "’")
  30. )
  31. )
  32. @minicli.cli
  33. def generate():
  34. template = environment.get_template("histoire.html")
  35. page = template.render(chapters=collection())
  36. open(FAMILLE / "histoire" / "index.html", "w").write(page)
  37. @minicli.cli
  38. def deploy():
  39. repository = "gitea-repositories/davidbgk/larlet-fr-famille.git"
  40. run(f"git archive --remote={repository} master | tar -x -C larlet-fr")
  41. print("Deployment done.")
  42. @minicli.wrap
  43. def perf_wrapper():
  44. start = perf_counter()
  45. yield
  46. elapsed = perf_counter() - start
  47. print(f"Done in {elapsed:.5f} seconds.")
  48. if __name__ == "__main__":
  49. with connect(hostname="larlet@ssh-larlet.alwaysdata.net"):
  50. minicli.run()