From d9df4947f46925f53e2deaf3523b43403934be80 Mon Sep 17 00:00:00 2001 From: Roland Date: Mon, 21 Sep 2026 08:24:28 +0200 Subject: [PATCH] - Feature Image funktioniert MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - neue Gallerie hinzugefügt --- CSharpGhostImporter/HtmlConverter.cs | 12 ++++++++++++ CSharpGhostImporter/PostFetcher.cs | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/CSharpGhostImporter/HtmlConverter.cs b/CSharpGhostImporter/HtmlConverter.cs index b3618b6..31c4b2a 100644 --- a/CSharpGhostImporter/HtmlConverter.cs +++ b/CSharpGhostImporter/HtmlConverter.cs @@ -187,6 +187,9 @@ namespace wp2ghost SetClasses(ghostGallery, "kg-card kg-gallery-card"); AddWideClass(ghostGallery, gallery); + // Neue Format-Prüfung: data-carousel-extra Attribut speichern + string carouselExtra = gallery.GetAttributeValue("data-carousel-extra", ""); + var container = htmlDoc.CreateElement("div"); container.AddClass("kg-gallery-container"); @@ -204,6 +207,7 @@ namespace wp2ghost AppendGalleryRows(htmlDoc, container, wrappers, GetGalleryColumns(gallery)); ghostGallery.AppendChild(container); + // Caption aus erstem figcaption im Gallery-Container extrahieren var captionNode = gallery.SelectSingleNode(".//figcaption"); if (captionNode != null && !string.IsNullOrWhiteSpace(captionNode.InnerText)) { @@ -213,6 +217,14 @@ namespace wp2ghost ghostGallery.AddClass("kg-card-hascaption"); } + // data-carousel-extra als Ghost-Attribut übertragen (falls vorhanden) + if (!string.IsNullOrEmpty(carouselExtra)) + { + var extraAttr = htmlDoc.CreateAttribute("data-carousel-extra"); + extraAttr.Value = carouselExtra; + ghostGallery.Attributes.Append(extraAttr); + } + gallery.ParentNode?.ReplaceChild(ghostGallery, gallery); count++; } diff --git a/CSharpGhostImporter/PostFetcher.cs b/CSharpGhostImporter/PostFetcher.cs index a8e38db..5375be8 100644 --- a/CSharpGhostImporter/PostFetcher.cs +++ b/CSharpGhostImporter/PostFetcher.cs @@ -121,6 +121,21 @@ namespace wp2ghost var parsedDate = DateTime.MinValue; var postDate = DateTime.TryParse(wpPost.Date, out parsedDate) ? parsedDate : new DateTime(2026, 9, 1); + // Featured Image: falls von der WP API nicht gesetzt, ersten Bild-URL aus HTML nehmen + if (string.IsNullOrEmpty(wpPost.FeaturedImage)) + { + var firstImgMatch = System.Text.RegularExpressions.Regex.Match(htmlContent, @"]*src=[""']([^""']+)[""'][^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase); + if (firstImgMatch.Success) + { + string firstImgUrl = firstImgMatch.Groups[1].Value; + if (IsInternalUrl(firstImgUrl, wpHost)) + { + wpPost.FeaturedImage = firstImgUrl; + Console.WriteLine($" [Featured Image] Aus HTML extrahiert (da API keine lieferte): {Path.GetFileName(new Uri(firstImgUrl).AbsolutePath)}"); + } + } + } + // Alle internen Bild-URLs aus dem HTML extrahieren (keine externen Links) var htmlImageUrls = ExtractImageUrls(htmlContent, wpHost);