This commit is contained in:
1 parent
23b1cb2966
commit
e9532e8878
30 files changed
+1835
-542
No files matched your search
@@ -1,4 +1,68 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
FILE: scripts/fix_frontmatter.py
|
||||
VERSION: 2.1.0 (2025-12-15)
|
||||
STATUS: Active
|
||||
COMPATIBILITY: v2.9.1 (Post-WP14/WP-15b)
|
||||
|
||||
Zweck:
|
||||
-------
|
||||
Repariert oder ergänzt fehlende Frontmatter-Felder in Markdown-Dateien.
|
||||
Erzeugt stabile IDs, erkennt Typen und erstellt vollständige Frontmatter-Struktur.
|
||||
|
||||
Funktionsweise:
|
||||
---------------
|
||||
1. Scannt alle Markdown-Dateien im Vault
|
||||
2. Für jede Datei:
|
||||
- Liest vorhandenes Frontmatter
|
||||
- Erkennt fehlende Felder (id, title, type, created)
|
||||
- Generiert fehlende Werte:
|
||||
* id: Stabile ID aus Pfad, Titel und Datum
|
||||
* title: Aus H1, Dateiname oder "Untitled"
|
||||
* type: Aus Pfad/Tags (journal, task, project, etc.)
|
||||
* created: Aus Dateiname oder mtime
|
||||
- Validiert Payload (optional)
|
||||
- Schreibt korrigiertes Frontmatter zurück
|
||||
|
||||
Ergebnis-Interpretation:
|
||||
------------------------
|
||||
- Ausgabe: JSON pro Datei mit Änderungen
|
||||
* path: Dateipfad
|
||||
* changes: Dict mit alten/neuen Werten
|
||||
* backup_path: Pfad zur Backup-Datei (falls --backup)
|
||||
- Exit-Code 0: Erfolgreich
|
||||
|
||||
Verwendung:
|
||||
-----------
|
||||
- Migration von Legacy-Vaults ohne Frontmatter
|
||||
- Reparatur beschädigter Frontmatter
|
||||
- Standardisierung von Frontmatter-Strukturen
|
||||
|
||||
Hinweise:
|
||||
---------
|
||||
- Erstellt Backups vor Änderungen (mit --backup)
|
||||
- Idempotent: Überspringt bereits vollständige Frontmatter
|
||||
- Nutzt Heuristiken für Typ-Erkennung (Pfad/Tags)
|
||||
|
||||
Aufruf:
|
||||
-------
|
||||
python3 -m scripts.fix_frontmatter --vault ./vault --apply
|
||||
python3 -m scripts.fix_frontmatter --vault ./vault --backup --apply
|
||||
|
||||
Parameter:
|
||||
----------
|
||||
--vault PATH Pfad zum Vault-Verzeichnis (erforderlich)
|
||||
--backup Erstellt Backup-Dateien vor Änderungen
|
||||
--apply Führt tatsächliche Änderungen durch (sonst Dry-Run)
|
||||
--validate Validiert Note-Payload nach Fix
|
||||
|
||||
Änderungen:
|
||||
-----------
|
||||
v2.1.0 (2025-12-15): Dokumentation aktualisiert
|
||||
- Hinweis: validate_note_payload existiert nicht mehr (wird entfernt)
|
||||
v1.0.0: Initial Release
|
||||
"""
|
||||
from __future__ import annotations
|
||||
import argparse, os, re, sys, json, shutil, time, hashlib
|
||||
from dataclasses import dataclass
|
||||
@@ -6,7 +70,7 @@ from typing import Dict, Tuple, Optional, List
|
||||
from slugify import slugify
|
||||
from app.core.parser import read_markdown, normalize_frontmatter
|
||||
from app.core.parser import FRONTMATTER_RE # für Re-Inject
|
||||
from app.core.validate_note import validate_note_payload
|
||||
# NOTE: validate_note_payload existiert nicht mehr - entfernt
|
||||
from app.core.ingestion.ingestion_note_payload import make_note_payload
|
||||
|
||||
DATE_IN_NAME = re.compile(r"(?P<y>\d{4})[-_\.]?(?P<m>\d{2})[-_\.]?(?P<d>\d{2})")
|
||||
|
||||
Reference in new issue
Block a user