Feature: Automatische Metadaten-Extraktion aus Frontmatter
- Neuer markdown_parser.py mit YAML-Frontmatter Extraktion - Unterstützung für drei Modi: Einzelne URL, YAML-Batch, Forgejo-Repo - Metadaten (name, description, tags, image, author) aus Frontmatter - Schema.org-Support für commonMetadata - Vereinfachte posts.yaml (nur URLs statt vollständiger Metadaten) - Aktualisierte Dokumentation (README.md, QUICKSTART.md) - Beispiel-Beitrag mit vollständigem Frontmatter
This commit is contained in:
parent
e3b19bb0df
commit
7a234be652
6 changed files with 880 additions and 180 deletions
225
README.md
225
README.md
|
|
@ -2,14 +2,18 @@
|
|||
|
||||
Automatisierter Workflow zum Erstellen von WordPress-Beiträgen aus Markdown-Dateien über die WordPress REST-API.
|
||||
|
||||
**Neu:** Metadaten werden automatisch aus dem YAML-Frontmatter der Markdown-Dateien extrahiert!
|
||||
|
||||
## Features
|
||||
|
||||
- ✅ **Automatische Metadaten-Extraktion**: name, description, tags, image, author aus YAML-Frontmatter
|
||||
- ✅ **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
|
||||
- ✅ **Medien-Upload**: Hochladen von Beitragsbildern mit Duplikatsprüfung
|
||||
- ✅ **Kategorien & Tags**: Automatische Erstellung fehlender Kategorien und Tags
|
||||
- ✅ **Flexible Quellen**: Unterstützt Markdown-URLs und lokale Dateien
|
||||
- ✅ **YAML-Konfiguration**: Einfache Verwaltung mehrerer Beiträge
|
||||
- ✅ **Flexible Quellen**: Unterstützt Markdown-URLs, lokale Dateien und Forgejo-Repositories
|
||||
- ✅ **Schema.org Support**: Versteht commonMetadata-Strukturen
|
||||
|
||||
## Voraussetzungen
|
||||
|
||||
|
|
@ -58,29 +62,31 @@ Automatisierter Workflow zum Erstellen von WordPress-Beiträgen aus Markdown-Dat
|
|||
|
||||
## Verwendung
|
||||
|
||||
### 1. YAML-Konfiguration erstellen
|
||||
### Modus 1: Einzelne URL (Am einfachsten!)
|
||||
|
||||
Erstellen Sie eine `posts.yaml`-Datei mit Ihren Beiträgen:
|
||||
Verarbeiten Sie eine einzelne Markdown-URL direkt:
|
||||
|
||||
```bash
|
||||
source .venv/bin/activate
|
||||
python workflow.py "https://example.com/artikel.md"
|
||||
```
|
||||
|
||||
Alle Metadaten (Titel, Tags, Kategorien, Bild) werden aus dem YAML-Frontmatter der Markdown-Datei extrahiert.
|
||||
|
||||
### Modus 2: Mehrere URLs aus YAML-Datei
|
||||
|
||||
Erstellen Sie eine `posts.yaml`-Datei:
|
||||
|
||||
```yaml
|
||||
# Einfache URL-Liste - Metadaten kommen aus dem Frontmatter!
|
||||
posts:
|
||||
- title: "Mein erster Beitrag"
|
||||
markdown_url: "https://raw.githubusercontent.com/user/repo/main/post.md"
|
||||
status: "draft" # draft, publish, pending, private
|
||||
categories:
|
||||
- "News"
|
||||
- "Tutorials"
|
||||
tags:
|
||||
- "WordPress"
|
||||
- "API"
|
||||
featured_image: "images/header.jpg"
|
||||
excerpt: "Eine kurze Zusammenfassung"
|
||||
|
||||
- title: "Lokaler Beitrag"
|
||||
markdown_file: "content/local-post.md"
|
||||
status: "publish"
|
||||
categories:
|
||||
- "Updates"
|
||||
- url: "https://example.com/artikel1.md"
|
||||
- url: "https://example.com/artikel2.md"
|
||||
- file: "content/lokaler-artikel.md"
|
||||
|
||||
# Optional: Metadaten überschreiben
|
||||
- url: "https://example.com/artikel3.md"
|
||||
status: "publish" # Überschreibt Status aus Frontmatter
|
||||
|
||||
settings:
|
||||
default_status: "draft"
|
||||
|
|
@ -88,26 +94,84 @@ settings:
|
|||
skip_duplicate_media: true
|
||||
```
|
||||
|
||||
### 2. Workflow ausführen
|
||||
|
||||
Aktivieren Sie zuerst die virtuelle Umgebung:
|
||||
Dann ausführen:
|
||||
|
||||
```bash
|
||||
source .venv/bin/activate
|
||||
```
|
||||
|
||||
Dann führen Sie das Workflow-Script aus:
|
||||
|
||||
```bash
|
||||
python workflow.py posts.yaml
|
||||
```
|
||||
|
||||
Oder ohne Angabe der Datei (verwendet `posts.yaml` als Standard):
|
||||
### Modus 3: Ganzes Forgejo/Gitea-Repository
|
||||
|
||||
Verarbeiten Sie alle Markdown-Dateien aus einem Repository:
|
||||
|
||||
```bash
|
||||
python workflow.py
|
||||
source .venv/bin/activate
|
||||
python workflow.py --repo "https://codeberg.org/user/repo" main
|
||||
```
|
||||
|
||||
Dies lädt automatisch alle `.md`-Dateien aus dem Repository und erstellt WordPress-Beiträge.
|
||||
|
||||
## Markdown-Frontmatter Format
|
||||
|
||||
Ihre Markdown-Dateien sollten YAML-Frontmatter enthalten:
|
||||
|
||||
```markdown
|
||||
---
|
||||
name: "Artikel-Titel"
|
||||
description: "Kurze Zusammenfassung für WordPress-Excerpt"
|
||||
image: "https://example.com/bild.jpg"
|
||||
tags:
|
||||
- WordPress
|
||||
- Tutorial
|
||||
- Open Source
|
||||
categories:
|
||||
- Tutorials
|
||||
author:
|
||||
- Max Mustermann
|
||||
---
|
||||
|
||||
# Artikel-Inhalt
|
||||
|
||||
Hier beginnt der eigentliche Markdown-Inhalt...
|
||||
```
|
||||
|
||||
### Unterstützte Frontmatter-Felder
|
||||
|
||||
Das System extrahiert automatisch:
|
||||
|
||||
- **Titel**: `name` oder `title`
|
||||
- **Excerpt**: `description` oder `summary`
|
||||
- **Beitragsbild**: `image` oder `cover.image`
|
||||
- **Tags**: `tags` (Liste oder kommagetrennt)
|
||||
- **Kategorien**: `categories` (Liste oder kommagetrennt)
|
||||
- **Autor**: `author` (String oder Liste)
|
||||
- **Status**: `status` oder aus `creativeWorkStatus`
|
||||
- **Datum**: `date` oder `datePublished`
|
||||
|
||||
### Schema.org Support
|
||||
|
||||
Das System versteht auch Schema.org-Metadaten:
|
||||
|
||||
```yaml
|
||||
---
|
||||
'@context': https://schema.org/
|
||||
type: LearningResource
|
||||
name: "Artikel-Titel"
|
||||
description: "Beschreibung"
|
||||
image: "https://example.com/bild.jpg"
|
||||
creator:
|
||||
- givenName: Max
|
||||
familyName: Mustermann
|
||||
type: Person
|
||||
tags:
|
||||
- Tag1
|
||||
- Tag2
|
||||
---
|
||||
```
|
||||
|
||||
Siehe `content/beispiel-beitrag.md` für ein vollständiges Beispiel.
|
||||
|
||||
## Struktur
|
||||
|
||||
```
|
||||
|
|
@ -117,11 +181,13 @@ newsimport/
|
|||
├── .gitignore # Git-Ignorier-Liste
|
||||
├── requirements.txt # Python-Abhängigkeiten
|
||||
├── wordpress_api.py # WordPress REST-API Client
|
||||
├── markdown_parser.py # YAML-Frontmatter Parser
|
||||
├── workflow.py # Haupt-Workflow Script
|
||||
├── posts.yaml # Beitrags-Konfiguration
|
||||
├── posts.yaml # Beitrags-Konfiguration (optional)
|
||||
├── README.md # Diese Datei
|
||||
├── QUICKSTART.md # Schnellstart-Anleitung
|
||||
├── content/ # Lokale Markdown-Dateien (optional)
|
||||
│ └── *.md
|
||||
│ └── beispiel-beitrag.md
|
||||
└── images/ # Lokale Bilder (optional)
|
||||
└── *.jpg/png
|
||||
```
|
||||
|
|
@ -163,33 +229,36 @@ existing_post_id = wp.check_post_exists("Titel")
|
|||
existing_media_id = wp.check_media_exists("bild.jpg")
|
||||
```
|
||||
|
||||
## YAML-Konfiguration
|
||||
## YAML-Konfiguration (posts.yaml)
|
||||
|
||||
### Beitrags-Felder
|
||||
### Vereinfachte Struktur
|
||||
|
||||
- `title` (erforderlich): Titel des Beitrags
|
||||
- `markdown_url`: URL zur Markdown-Datei
|
||||
- `markdown_file`: Pfad zu lokaler Markdown-Datei
|
||||
- `content`: Direkter Markdown-Inhalt
|
||||
- `status`: `draft`, `publish`, `pending`, `private`
|
||||
- `categories`: Liste von Kategorie-Namen
|
||||
- `tags`: Liste von Tag-Namen
|
||||
- `featured_image`: Pfad oder URL zum Beitragsbild
|
||||
- `excerpt`: Kurze Zusammenfassung
|
||||
- `author`: Autor-Username
|
||||
Metadaten werden automatisch aus dem Frontmatter extrahiert:
|
||||
|
||||
```yaml
|
||||
posts:
|
||||
- url: "https://example.com/artikel.md" # URL zur Markdown-Datei
|
||||
- file: "content/artikel.md" # Oder lokale Datei
|
||||
|
||||
# Optional: Metadaten überschreiben
|
||||
- url: "https://example.com/artikel2.md"
|
||||
status: "publish" # Überschreibt Frontmatter
|
||||
categories: # Ergänzt Frontmatter-Kategorien
|
||||
- "Extra-Kategorie"
|
||||
```
|
||||
|
||||
### Globale Einstellungen
|
||||
|
||||
```yaml
|
||||
settings:
|
||||
default_status: "draft" # Standard-Status für Beiträge
|
||||
default_author: "admin" # Standard-Autor
|
||||
default_status: "draft" # Fallback wenn nicht im Frontmatter
|
||||
default_author: "admin" # Fallback wenn nicht im Frontmatter
|
||||
skip_duplicates: true # Bestehende Beiträge überspringen
|
||||
skip_duplicate_media: true # Bestehende Medien überspringen
|
||||
markdown_extensions: # Markdown-Erweiterungen
|
||||
- tables
|
||||
- fenced_code
|
||||
- footnotes
|
||||
- extra
|
||||
- codehilite
|
||||
- toc
|
||||
```
|
||||
|
||||
## Duplikatsprüfung
|
||||
|
|
@ -202,41 +271,45 @@ Vor dem Upload wird geprüft, ob eine Datei mit dem gleichen Namen bereits exist
|
|||
|
||||
## Beispiele
|
||||
|
||||
### Beispiel 1: Einfacher Beitrag von URL
|
||||
### Beispiel 1: Einzelne URL direkt
|
||||
|
||||
```yaml
|
||||
posts:
|
||||
- title: "News Update"
|
||||
markdown_url: "https://example.com/news.md"
|
||||
status: "publish"
|
||||
```bash
|
||||
python workflow.py "https://example.com/artikel.md"
|
||||
```
|
||||
|
||||
### Beispiel 2: Beitrag mit Kategorien, Tags und Bild
|
||||
### Beispiel 2: Lokale Datei
|
||||
|
||||
```yaml
|
||||
posts:
|
||||
- title: "Tutorial: WordPress REST-API"
|
||||
markdown_url: "https://example.com/tutorial.md"
|
||||
status: "draft"
|
||||
categories:
|
||||
- "Tutorials"
|
||||
- "WordPress"
|
||||
tags:
|
||||
- "REST-API"
|
||||
- "Entwicklung"
|
||||
- "PHP"
|
||||
featured_image: "https://example.com/images/header.jpg"
|
||||
excerpt: "Lernen Sie die WordPress REST-API kennen"
|
||||
```bash
|
||||
python workflow.py "content/beispiel-beitrag.md"
|
||||
```
|
||||
|
||||
### Beispiel 3: Lokale Dateien
|
||||
### Beispiel 3: Mehrere URLs aus YAML
|
||||
|
||||
```yaml
|
||||
posts:
|
||||
- title: "Lokaler Inhalt"
|
||||
markdown_file: "content/article.md"
|
||||
status: "publish"
|
||||
featured_image: "images/local-image.jpg"
|
||||
- url: "https://example.com/artikel1.md"
|
||||
- url: "https://example.com/artikel2.md"
|
||||
- file: "content/lokaler-artikel.md"
|
||||
```
|
||||
|
||||
```bash
|
||||
python workflow.py posts.yaml
|
||||
```
|
||||
|
||||
### Beispiel 4: Forgejo-Repository
|
||||
|
||||
```bash
|
||||
python workflow.py --repo "https://codeberg.org/user/repo" main
|
||||
```
|
||||
|
||||
### Beispiel 5: Metadaten überschreiben
|
||||
|
||||
```yaml
|
||||
posts:
|
||||
- url: "https://example.com/artikel.md"
|
||||
status: "publish" # Überschreibt Status aus Frontmatter
|
||||
categories: # Ergänzt Kategorien aus Frontmatter
|
||||
- "Extra-Kategorie"
|
||||
```
|
||||
|
||||
## Fehlerbehebung
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue