Nouvelle version de Zola et petites corrections
This commit is contained in:
1 parent
7e09d12345
commit
58bcc189ab
9 files changed
+92
-22
No files matched your search
@@ -1,8 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Vérifie que chaque fiche contient les champs prévus pour son modèle."""
|
||||
|
||||
import re
|
||||
import sys
|
||||
import tomllib
|
||||
import unicodedata
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
@@ -25,6 +27,8 @@ COMMON_FIELDS = {
|
||||
"draft": bool,
|
||||
}
|
||||
|
||||
MZL_FILENAME_RE = re.compile(r"mzl-([0-9]{3})")
|
||||
|
||||
|
||||
class Validator:
|
||||
def __init__(self) -> None:
|
||||
@@ -68,6 +72,46 @@ def read_front_matter(
|
||||
return None
|
||||
|
||||
|
||||
def check_filename(
|
||||
path: Path,
|
||||
section: str,
|
||||
validator: Validator,
|
||||
) -> None:
|
||||
stem = path.stem
|
||||
normalized = unicodedata.normalize("NFC", stem)
|
||||
if stem != normalized:
|
||||
validator.error(path, "nom de fichier non normalisé en Unicode NFC")
|
||||
|
||||
if section == "signes":
|
||||
match = MZL_FILENAME_RE.fullmatch(stem)
|
||||
if match is None or not 1 <= int(match.group(1)) <= 999:
|
||||
validator.error(path, "un signe doit être nommé mzl-NNN.md (001 à 999)")
|
||||
return
|
||||
|
||||
allow_leading_hyphen = section == "vocabulaire"
|
||||
body = stem[1:] if stem.startswith("-") else stem
|
||||
if stem.startswith("-") and not allow_leading_hyphen:
|
||||
validator.error(
|
||||
path,
|
||||
"seul le vocabulaire accepte un nom commençant par un tiret",
|
||||
)
|
||||
return
|
||||
|
||||
if (
|
||||
not body
|
||||
or stem in {".", "..", "_index"}
|
||||
or stem != stem.lower()
|
||||
or stem.endswith("-")
|
||||
or "--" in stem
|
||||
or not all(character.isalnum() or character == "-" for character in body)
|
||||
):
|
||||
validator.error(
|
||||
path,
|
||||
"nom de fichier invalide : utiliser des lettres Unicode minuscules, "
|
||||
"des chiffres et des tirets",
|
||||
)
|
||||
|
||||
|
||||
def check_type(
|
||||
value: Any,
|
||||
expected_type: type,
|
||||
@@ -189,6 +233,8 @@ def main() -> int:
|
||||
validator.error(path, f"section inconnue : {section}")
|
||||
continue
|
||||
|
||||
check_filename(path, section, validator)
|
||||
|
||||
result = read_front_matter(path, validator)
|
||||
if result is None:
|
||||
continue
|
||||
|
||||
Reference in new issue
Block a user