51 lines
No EOL
1.4 KiB
PHP
51 lines
No EOL
1.4 KiB
PHP
<?php
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
use Symfony\Component\Yaml\Yaml;
|
|
|
|
$url = 'https://git.rpi-virtuell.de/Comenius-Institut/FOERBICO/raw/branch/main/Website/content/posts/2025-03-20-Workshop-KlimaOER/index.md';
|
|
|
|
// Markdown-Inhalt von der URL laden
|
|
$content = file_get_contents($url);
|
|
if ($content === false) {
|
|
die("Fehler: Konnte Datei nicht laden.");
|
|
}
|
|
|
|
// YAML-Header und Markdown-Inhalt trennen
|
|
$parts = explode('---', $content);
|
|
if (count($parts) < 3) {
|
|
die("Fehler: Ungültiges Dateiformat - YAML-Header nicht gefunden.");
|
|
}
|
|
|
|
$yamlContent = trim($parts[1]);
|
|
$markdownContent = trim($parts[2]);
|
|
|
|
// YAML in JSON konvertieren
|
|
try {
|
|
$parsedYaml = Yaml::parse($yamlContent);
|
|
$jsonOutput = json_encode(
|
|
$parsedYaml,
|
|
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
|
|
);
|
|
} catch (Exception $e) {
|
|
die("YAML-Parsing Fehler: " . $e->getMessage());
|
|
}
|
|
|
|
// Hauptüberschrift aus Markdown entfernen
|
|
$markdownLines = explode("\n", $markdownContent);
|
|
foreach ($markdownLines as $key => $line) {
|
|
if (strpos(trim($line), '# ') === 0) {
|
|
unset($markdownLines[$key]);
|
|
break;
|
|
}
|
|
}
|
|
$cleanedMarkdown = implode("\n", $markdownLines);
|
|
|
|
// Ergebnisse speichern
|
|
file_put_contents('metadata.json', $jsonOutput);
|
|
file_put_contents('content.md', $cleanedMarkdown);
|
|
|
|
echo "Erfolgreich verarbeitet:\n";
|
|
echo "- JSON-Metadaten: metadata.json\n";
|
|
echo "- Bereinigter Inhalt: content.md\n"; |