X-Git-Url: https://fortfriendship.online/gitweb/gnargle.github.io.git/blobdiff_plain/598be5a9f8cf5eae9e6d42035d7a328c87f372f7..519ed859ee5bc56560d335f893b4855b4661a7d0:/RSSGen/Program.cs diff --git a/RSSGen/Program.cs b/RSSGen/Program.cs index f64ac3f..1224192 100644 --- a/RSSGen/Program.cs +++ b/RSSGen/Program.cs @@ -1,12 +1,24 @@ -using RssFeedGenerator; +using OpenGraphNet; +using RssFeedGenerator; using System; using System.Collections.Generic; using System.IO; +using System.Runtime.InteropServices; // See https://aka.ms/new-console-template for more information Console.WriteLine("Scanning entries folder for latest files"); -var filePaths = Directory.EnumerateFiles(Path.Combine(Directory.GetCurrentDirectory(), "../../../../entries")); +var folder = String.Empty; + +if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) +{ + folder = Path.Combine(Directory.GetCurrentDirectory(), "../entries"); +} +else +{ + folder = Path.Combine(Directory.GetCurrentDirectory(), "../../../../entries"); +} +var filePaths = Directory.EnumerateFiles(folder); var fileInfos = new List(); if (filePaths.Any()) @@ -22,7 +34,16 @@ if (filePaths.Any()) Console.WriteLine("Scanning projects folder for latest files"); -filePaths = Directory.EnumerateFiles(Path.Combine(Directory.GetCurrentDirectory(), "../../../../projects")); +if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) +{ + folder = Path.Combine(Directory.GetCurrentDirectory(), "../projects"); +} +else +{ + folder = Path.Combine(Directory.GetCurrentDirectory(), "../../../../projects"); +} + +filePaths = Directory.EnumerateFiles(folder); if (filePaths.Any()) { @@ -45,15 +66,25 @@ myRSS.channel = new rssChannel description = "blog entries for athene.gay", language = "en-GB", link = "https://athene.gay", - item = new List() + item = new List(), + link1 = new link + { + href = "https://athene.gay/feed.xml", + rel = "self", + type = "application/rss+xml", + } }; foreach (var file in fileInfos) { + var htmlString = File.ReadAllText(file.FullName); + OpenGraph graph = OpenGraph.ParseHtml(htmlString); + var publishDate = DateTime.Parse(graph.Metadata["article:published_time"].First()); var item = new rssChannelItem() { - title = Path.GetFileNameWithoutExtension(file.Name), - pubDate = file.CreationTimeUtc.ToString(), + title = graph.Title, + description = graph.Metadata["og:description"].First(), + pubDate = publishDate.ToString("r"), }; if (file.FullName.Contains("entries")) { @@ -63,12 +94,26 @@ foreach (var file in fileInfos) { item.link = "https://athene.gay/projects/" + Path.GetFileName(file.Name); } + item.guid = new rssChannelItemGuid() + { + isPermaLink = true, + Value = item.link + }; myRSS.channel.item.Add(item); } var output = Generator.SerializeRSS(myRSS); -var rssPath = Path.Combine(Directory.GetCurrentDirectory(), "../../../../feed.xml"); +var rssPath = String.Empty; + +if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) +{ + rssPath = Path.Combine(Directory.GetCurrentDirectory(), "../feed.xml"); +} +else +{ + rssPath = Path.Combine(Directory.GetCurrentDirectory(), "../../../../feed.xml"); +} if (File.Exists(rssPath)) {