Meilleurs scripts
This commit is contained in:
@@ -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 d’une 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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user