From 694d4b74a4a5dd3d8eb9aabdf62f70a11edacd0f Mon Sep 17 00:00:00 2001 From: Florestan Bredow Date: Sun, 27 Jul 2025 16:49:31 +0200 Subject: [PATCH] =?UTF-8?q?Ajoute=20un=20cache=20pour=20l'HTML=20g=C3=A9n?= =?UTF-8?q?=C3=A9r=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blog/page.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/blog/page.py b/blog/page.py index ce4a260..3ee675f 100644 --- a/blog/page.py +++ b/blog/page.py @@ -14,7 +14,7 @@ def new_page(title: str, path: Path) -> Path: today = date.today().strftime("%Y-%m-%d") - filename = path + '/' + re.sub("[^a-zA-Z0-9-]", "_", title) + ".md" + filename = path + "/" + re.sub("[^a-zA-Z0-9-]", "_", title) + ".md" id = uuid.uuid4() content = textwrap.dedent( f"""\ @@ -43,6 +43,8 @@ class Page: md_content = "" filename = "" + _cache = "" + def __init__(self, filename: Path): """Constructeur : nouvelle page""" self.filename = filename @@ -84,12 +86,14 @@ class Page: def html(self) -> str: """Convertit le markdown en html""" - return markdown.markdown( - self.md_content, extensions=["codehilite", "fenced_code"] - ) + if not self._cache: + self._cache = markdown.markdown( + self.md_content, extensions=["codehilite", "fenced_code"] + ) + return self._cache - def html_template(self, template: jinja2.Template) -> str: + def html_template(self, template: jinja2.Template) -> str: """Convertit la page en html a partir d'un template jinja2""" title = self.meta["title"] or "Sans titre" date = self.meta["date"] or None