Meilleurs scripts

This commit is contained in:
julien
2026-08-06 16:42:42 +02:00
parent cc1b03b78e
commit 7a0e75442c
6 changed files with 242 additions and 357 deletions
+11 -4
View File
@@ -8,6 +8,8 @@ from datetime import datetime
from pathlib import Path
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
from _schema import CONTENT_SECTIONS, UPDATED_LINE_RE
ROOT = Path(__file__).resolve().parent.parent
CONTENT = (ROOT / "src" / "content").resolve()
@@ -15,7 +17,6 @@ FRONT_MATTER_RE = re.compile(
r"\A\+\+\+\r?\n(?P<body>.*?)(?:\r?\n\+\+\+(?=\r?\n|\Z))",
re.DOTALL,
)
UPDATED_RE = re.compile(r"(?m)^(?:#\s*)?updated\s*=.*?(?=\r?$)")
def parse_args() -> argparse.Namespace:
@@ -39,8 +40,14 @@ def resolve_path(value: str) -> Path:
raise ValueError("la fiche doit se trouver dans src/content/")
if not path.is_file():
raise ValueError(f"fichier introuvable : {path}")
if path.suffix != ".md" or path.name == "_index.md":
raise ValueError("le chemin doit désigner une fiche Markdown, pas un index")
relative_path = path.relative_to(CONTENT)
if (
path.suffix != ".md"
or path.name == "_index.md"
or len(relative_path.parts) == 1
or relative_path.parts[0] not in CONTENT_SECTIONS
):
raise ValueError("le chemin doit désigner une fiche dune section connue")
return path
@@ -52,7 +59,7 @@ def update_timestamp(path: Path) -> str:
if front_matter is None:
raise ValueError("front matter TOML délimité par +++ absent")
matches = list(UPDATED_RE.finditer(front_matter.group("body")))
matches = list(UPDATED_LINE_RE.finditer(front_matter.group("body")))
if len(matches) != 1:
raise ValueError("la fiche doit contenir exactement une ligne updated")