Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
694d4b74a4 |
12
blog/page.py
12
blog/page.py
@@ -14,7 +14,7 @@ def new_page(title: str, path: Path) -> Path:
|
|||||||
|
|
||||||
today = date.today().strftime("%Y-%m-%d")
|
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()
|
id = uuid.uuid4()
|
||||||
content = textwrap.dedent(
|
content = textwrap.dedent(
|
||||||
f"""\
|
f"""\
|
||||||
@@ -43,6 +43,8 @@ class Page:
|
|||||||
md_content = ""
|
md_content = ""
|
||||||
filename = ""
|
filename = ""
|
||||||
|
|
||||||
|
_cache = ""
|
||||||
|
|
||||||
def __init__(self, filename: Path):
|
def __init__(self, filename: Path):
|
||||||
"""Constructeur : nouvelle page"""
|
"""Constructeur : nouvelle page"""
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
@@ -84,10 +86,12 @@ class Page:
|
|||||||
|
|
||||||
def html(self) -> str:
|
def html(self) -> str:
|
||||||
"""Convertit le markdown en html"""
|
"""Convertit le markdown en html"""
|
||||||
return markdown.markdown(
|
if not self._cache:
|
||||||
self.md_content, extensions=["codehilite", "fenced_code"]
|
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"""
|
"""Convertit la page en html a partir d'un template jinja2"""
|
||||||
|
Reference in New Issue
Block a user