using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.Json.Serialization; using System.Threading.Tasks; namespace wp2ghost { public class IdsResponse { [JsonPropertyName("count")] public int Count { get; set; } [JsonPropertyName("post_type")] public string? PostType { get; set; } [JsonPropertyName("ids")] public List? Ids { get; set; } } public class WpPostResponse { [JsonPropertyName("id")] public int Id { get; set; } [JsonPropertyName("title")] public string? Title { get; set; } [JsonPropertyName("slug")] public string? Slug { get; set; } // Veröffentlichungsdatum in der Ortszeit des Blogs (ohne Zeitzone) [JsonPropertyName("date")] public string? Date { get; set; } // Dasselbe in UTC — ab Plugin-Version mit date_gmt [JsonPropertyName("date_gmt")] public string? DateGmt { get; set; } [JsonPropertyName("content")] public string? Content { get; set; } [JsonPropertyName("excerpt")] public string? Excerpt { get; set; } [JsonPropertyName("featured_image")] public string? FeaturedImage { get; set; } [JsonPropertyName("categories")] public List? Categories { get; set; } = new(); [JsonPropertyName("tags")] public List? Tags { get; set; } = new(); [JsonPropertyName("keywords")] public string? Keywords { get; set; } [JsonPropertyName("comments")] public List? Comments { get; set; } = new(); [JsonPropertyName("media_files")] public List? MediaFiles { get; set; } = new(); } public class WpCategory { [JsonPropertyName("id")] public int Id { get; set; } [JsonPropertyName("name")] public string? Name { get; set; } [JsonPropertyName("slug")] public string? Slug { get; set; } } // Datumsangaben für Ghost: immer UTC im Format 2022-11-19T09:30:00.000Z public static class DateHelper { private const string GhostFormat = "yyyy-MM-dd'T'HH:mm:ss.000'Z'"; /// /// Wandelt ein Datum in UTC um. Ein Datum ohne Zeitzone (so liefert es WordPress) wird /// als Ortszeit dieses Rechners gedeutet. Liefert null, wenn es nicht lesbar ist. /// public static string? ToGhostUtc(string? date) => Convert(date, System.Globalization.DateTimeStyles.AssumeLocal); /// Wie ToGhostUtc, aber ein Datum ohne Zeitzone gilt als UTC (WordPress "date_gmt"). public static string? FromGmt(string? date) => Convert(date, System.Globalization.DateTimeStyles.AssumeUniversal); private static string? Convert(string? date, System.Globalization.DateTimeStyles assume) { if (string.IsNullOrWhiteSpace(date)) return null; if (!DateTimeOffset.TryParse(date, System.Globalization.CultureInfo.InvariantCulture, assume, out var parsed)) return null; if (parsed.Year < 1990) return null; // WordPress-Platzhalter 0000-00-00 return parsed.UtcDateTime.ToString(GhostFormat, System.Globalization.CultureInfo.InvariantCulture); } } // Kategorien, die nie nach Ghost übernommen werden public static class CategoryRules { private static readonly string[] IgnoredNames = { "Allgemein" }; public static bool IsIgnored(string? name) => IgnoredNames.Contains(System.Net.WebUtility.HtmlDecode(name ?? "").Trim(), StringComparer.OrdinalIgnoreCase); public static bool IsIgnored(WpCategory category) => IsIgnored(category.Name) || IsIgnored(category.Slug); } public class WpComment { [JsonPropertyName("id")] public int Id { get; set; } [JsonPropertyName("author_name")] public string? AuthorName { get; set; } [JsonPropertyName("author_email")] public string? AuthorEmail { get; set; } [JsonPropertyName("author_url")] public string? AuthorUrl { get; set; } [JsonPropertyName("content")] public string? Content { get; set; } [JsonPropertyName("date")] public string? Date { get; set; } // Ab Plugin-Version mit Kommentar-Typ: "comment", "pingback", "like", "repost" ... [JsonPropertyName("type")] public string? Type { get; set; } [JsonPropertyName("parent")] public int Parent { get; set; } } }