Fix: Frontmatter mit Hash-Kommentaren und Debug-Ausgaben

Fixes:
- Unterstützung für flaches Frontmatter (wenn #commonMetadata: als Kommentar)
- creativeWorkStatus direkt im Frontmatter wird jetzt erkannt
- datePublished direkt im Frontmatter wird jetzt erkannt
- Status 'Published' wird zu 'publish' konvertiert (mit 'publish' in lowercase)
- date_gmt für explizite Datumskontrolle hinzugefügt

Debug-Ausgaben:
- Tag-Verarbeitung: Zeigt gefundene Tags und IDs
- Post-Erstellung: Zeigt gesendete Daten (Tags, Kategorien, Datum)
- WordPress-Response: Zeigt zurückgegebene Tags und Datum
- Verbesserte Erfolgsmeldung mit 

Getestet mit content/beispiel-beitrag.md:
 Status: publish
 Datum: 2025-09-02
 Tags: 6 Stück korrekt extrahiert
This commit is contained in:
Jörg Lohrer 2025-10-01 09:22:33 +02:00
parent c269105cd0
commit 99a4a9408f
3 changed files with 47 additions and 3 deletions

View file

@ -137,21 +137,31 @@ def extract_wordpress_metadata(frontmatter: Dict[str, Any],
# Status extrahieren (falls vorhanden)
if 'status' in frontmatter:
metadata['status'] = frontmatter['status']
elif 'creativeWorkStatus' in frontmatter:
# Direkt im Frontmatter (wenn #commonMetadata: als Kommentar)
work_status = frontmatter.get('creativeWorkStatus', '').lower()
if 'publish' in work_status:
metadata['status'] = 'publish'
elif work_status == 'draft':
metadata['status'] = 'draft'
elif isinstance(frontmatter.get('#commonMetadata'), dict):
# Verschachtelt in #commonMetadata
common = frontmatter['#commonMetadata']
work_status = common.get('creativeWorkStatus', '').lower()
if work_status == 'published':
if 'publish' in work_status:
metadata['status'] = 'publish'
elif work_status == 'draft':
metadata['status'] = 'draft'
# Datum extrahieren (falls vorhanden)
# Priorität: date > datePublished > (aus commonMetadata) > (aus staticSiteGenerator)
# Priorität: date > datePublished > (direkt) > (aus commonMetadata) > (aus staticSiteGenerator)
if 'date' in frontmatter:
metadata['date'] = str(frontmatter['date'])
elif 'datePublished' in frontmatter:
# Direkt im Frontmatter (wenn #commonMetadata: als Kommentar oder als Feld)
metadata['date'] = str(frontmatter['datePublished'])
elif isinstance(frontmatter.get('#commonMetadata'), dict):
# Verschachtelt in #commonMetadata
common = frontmatter['#commonMetadata']
if 'datePublished' in common:
metadata['date'] = str(common['datePublished'])

View file

@ -224,12 +224,31 @@ class WordPressAPI:
if tags:
post_data['tags'] = tags
# Debug: Zeige was gesendet wird
print(f"Erstelle Beitrag mit Daten:")
print(f" - Status: {status}")
if tags:
print(f" - Tags: {tags}")
if categories:
print(f" - Kategorien: {categories}")
if 'date' in post_data:
print(f" - Datum: {post_data['date']}")
if 'date_gmt' in post_data:
print(f" - Datum GMT: {post_data['date_gmt']}")
# Beitrag erstellen
try:
response = self._post('posts', data=post_data)
post = response.json()
post_id = post['id']
print(f"Beitrag '{title}' erstellt (ID: {post_id}, Status: {status})")
print(f"✅ Beitrag '{title}' erstellt (ID: {post_id}, Status: {status})")
# Debug: Zeige was WordPress zurückgibt
if 'tags' in post and post['tags']:
print(f" WordPress-Tags: {post['tags']}")
if 'date' in post:
print(f" WordPress-Datum: {post['date']}")
return post_id
except requests.exceptions.RequestException as e:

View file

@ -202,10 +202,17 @@ def process_post(wp_api: WordPressAPI, post_config: Dict[str, Any],
tag_ids = []
tags_list = metadata.get('tags') or post_config.get('tags') or []
if tags_list:
print(f"Tags aus Frontmatter: {tags_list}")
for tag_name in tags_list:
tag_id = wp_api.get_or_create_tag(tag_name)
if tag_id:
tag_ids.append(tag_id)
print(f" → Tag '{tag_name}' ID: {tag_id}")
if tag_ids:
print(f"Gesamt Tag-IDs: {tag_ids}")
# Beitragsbild verarbeiten
featured_media_id = None
@ -244,8 +251,16 @@ def process_post(wp_api: WordPressAPI, post_config: Dict[str, Any],
# Wenn nur Datum (YYYY-MM-DD), füge Uhrzeit hinzu
if len(publish_date) == 10: # Format: 2025-09-02
publish_date = f"{publish_date}T00:00:00"
# Für draft-Posts: Setze sowohl 'date' als auch 'date_gmt'
# Für published-Posts: WordPress setzt automatisch bei Veröffentlichung
extra_fields['date'] = publish_date
# date_gmt für explizite Kontrolle (ohne Zeitzone)
extra_fields['date_gmt'] = publish_date
print(f"Veröffentlichungsdatum: {publish_date}")
if status == 'draft':
print(f" (Hinweis: Datum wird erst beim Veröffentlichen aktiv)")
# Beitrag erstellen
skip_duplicates = global_settings.get('skip_duplicates', True)