Ajoute le flux atom

This commit is contained in:
2025-07-17 18:12:51 +02:00
parent c1b730d396
commit 4c49d4e96a
4 changed files with 71 additions and 25 deletions

View File

@@ -1,6 +1,7 @@
import re
import os
import yaml
import uuid
import jinja2
import textwrap
import markdown
@@ -14,12 +15,13 @@ 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"
id = uuid.uuid4()
content = textwrap.dedent(
f"""\
---
date: {today}
title: {title}
id: {id}
category:
tags:
-
@@ -55,7 +57,7 @@ class Page:
if "date" not in self.meta or type(self.meta["date"]) is not date:
self.meta["date"] = date(1970, 1, 1)
def __getattr__(self, name):
def __getattr__(self, name: str):
if name not in self.meta:
raise AttributeError(f"L'attribut '{name}' n'existe pas.")
@@ -80,14 +82,19 @@ class Page:
meta += line + "\n"
return meta, markdown
def html(self, template: jinja2.Template) -> str:
def html(self) -> str:
"""Convertit le markdown en html"""
return markdown.markdown(
self.md_content, extensions=["codehilite", "fenced_code"]
)
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
return template.render(
title=title,
date=date,
content=markdown.markdown(
self.md_content, extensions=["codehilite", "fenced_code"]
),
content=self.html(),
)