Ajoute un cache pour l'HTML généré
This commit is contained in:
		
							
								
								
									
										14
									
								
								blog/page.py
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user