From 85f58e252829f0996228e06cc5d7ab256d1d4258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Lohrer?= Date: Wed, 5 Nov 2025 05:32:20 +0100 Subject: [PATCH] Feature: Map authors as tags in Vorname_Nachname format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added format_author_as_tag() function to convert author names to tag format - Author names automatically added to tags with spaces replaced by underscores - Example: 'Jörg Lohrer' → 'Jörg_Lohrer' tag - Enables author filtering via WordPress tag taxonomy - Updated documentation to reflect new author handling approach - Version bump to 0.3.0 --- CHANGELOG.md | 31 +++++++++++++++++++++++++++++++ README.md | 8 +++++--- markdown_parser.py | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab250b0..4f10847 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,36 @@ # Changelog +## Version 0.3.0 (2025-10-01) + +### Feature - Autor-zu-Tag-Mapping 🏷️ + +**Neues Feature:** Autoren werden automatisch als Tags hinzugefügt! + +**Funktion:** +- Autor aus Frontmatter wird extrahiert (`author`, `#staticSiteGenerator.author`, `#commonMetadata.creator`) +- Autor-Name wird automatisch als Tag im Format `Vorname_Nachname` hinzugefügt +- Leerzeichen werden durch Unterstriche ersetzt +- Mehrfache Unterstriche werden konsolidiert + +**Beispiel:** +```yaml +author: Jörg Lohrer +tags: + - OER + - Community +``` + +**Ergebnis:** +- Tags in WordPress: `OER`, `Community`, `Jörg_Lohrer` +- Filterung nach Autoren über WordPress-Tag-Taxonomie möglich + +**Technische Details:** +- Neue Funktion `format_author_as_tag()` in `markdown_parser.py` +- Autor-Tag wird nur hinzugefügt, wenn Autor vorhanden und noch nicht in Tags +- Integration in `extract_wordpress_metadata()` nach Autor-Extraktion + +--- + ## Version 0.2.2 (2025-10-01) ### Bugfix - Kritisch! 🐛 diff --git a/README.md b/README.md index 2176a92..02e3f19 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,10 @@ Automatisierter Workflow zum Erstellen von WordPress-Beiträgen aus Markdown-Dat ## ⚠️ Bekannte Einschränkungen **Autor-Zuordnung:** -- Beiträge werden aktuell immer dem importierenden WordPress-Benutzer zugeordnet -- Der `author` aus dem Frontmatter wird extrahiert, aber nicht mit WordPress-Benutzern abgeglichen -- **Zu entwickeln:** Automatisches Mapping von Frontmatter-Autoren zu WordPress-User-IDs oder manuelle Zuordnungs-Konfiguration +- Beiträge werden immer dem importierenden WordPress-Benutzer zugeordnet (WordPress REST-API Limitation) +- Der `author` aus dem Frontmatter wird automatisch als **Tag** im Format `Vorname_Nachname` hinzugefügt +- Beispiel: `author: Jörg Lohrer` → Tag: `Jörg_Lohrer` +- Dies ermöglicht die Filterung nach Autoren über die WordPress-Tag-Taxonomie **Forgejo-Repository-Import:** - Die Batch-Verarbeitung ganzer Repositories wurde noch nicht ausreichend getestet @@ -21,6 +22,7 @@ Automatisierter Workflow zum Erstellen von WordPress-Beiträgen aus Markdown-Dat ## Features - ✅ **Automatische Metadaten-Extraktion**: name, description, tags, image, author aus YAML-Frontmatter +- ✅ **Autor-zu-Tag-Mapping**: Autoren werden automatisch als Tags im Format `Vorname_Nachname` hinzugefügt - ✅ **Drei Verwendungsmodi**: Einzelne URL, YAML-Batch, Forgejo-Repository - ✅ **Duplikatsprüfung**: Verhindert das doppelte Erstellen von Beiträgen und Medien - ✅ **Markdown zu HTML**: Automatische Konvertierung von Markdown-Inhalten diff --git a/markdown_parser.py b/markdown_parser.py index 03df5a1..18a15be 100644 --- a/markdown_parser.py +++ b/markdown_parser.py @@ -39,6 +39,29 @@ def extract_frontmatter(markdown_content: str) -> tuple[Optional[Dict[str, Any]] return None, markdown_content +def format_author_as_tag(author_name: str) -> str: + """ + Formatiert einen Autornamen als Tag im Format Vorname_Nachname + + Args: + author_name: Autorenname (z.B. "Max Mustermann" oder "Max") + + Returns: + Tag-formatierter Name (z.B. "Max_Mustermann") + """ + # Entferne führende/nachfolgende Leerzeichen + author_name = author_name.strip() + + # Ersetze Leerzeichen durch Unterstriche + tag_name = author_name.replace(' ', '_') + + # Entferne mehrfache Unterstriche + while '__' in tag_name: + tag_name = tag_name.replace('__', '_') + + return tag_name + + def extract_wordpress_metadata(frontmatter: Dict[str, Any], default_author: str = "admin") -> Dict[str, Any]: """ @@ -94,6 +117,10 @@ def extract_wordpress_metadata(frontmatter: Dict[str, Any], elif isinstance(tags, str): metadata['tags'] = [t.strip() for t in tags.split(',')] + # Initialisiere tags falls nicht vorhanden + if 'tags' not in metadata: + metadata['tags'] = [] + # Kategorien extrahieren (falls vorhanden) if 'categories' in frontmatter: categories = frontmatter['categories'] @@ -134,6 +161,15 @@ def extract_wordpress_metadata(frontmatter: Dict[str, Any], if 'author' not in metadata: metadata['author'] = default_author + # Autor als Tag hinzufügen (Format: Vorname_Nachname) + if metadata.get('author'): + author_tag = format_author_as_tag(metadata['author']) + # Füge Autor-Tag zu den Tags hinzu, falls noch nicht vorhanden + if author_tag and author_tag not in metadata.get('tags', []): + if 'tags' not in metadata: + metadata['tags'] = [] + metadata['tags'].append(author_tag) + # Status extrahieren (falls vorhanden) if 'status' in frontmatter: metadata['status'] = frontmatter['status']