X-Git-Url: https://fortfriendship.online/gitweb/gnargle.github.io.git/blobdiff_plain/0f7866c338a2cbab0d34dd02bc62838b5eb5d54f..76c934d13a0a0dda31c3b8541c39ed2c343d56f6:/RSSGen/Program.cs?ds=sidebyside diff --git a/RSSGen/Program.cs b/RSSGen/Program.cs new file mode 100644 index 0000000..1af488a --- /dev/null +++ b/RSSGen/Program.cs @@ -0,0 +1,76 @@ +using RssFeedGenerator; +using System; +using System.Collections.Generic; +using System.IO; + +// 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 fileInfos = new List(); + +if (filePaths.Any()) +{ + foreach (var path in filePaths) + { + if (Path.GetFileNameWithoutExtension(path).Equals("template", StringComparison.InvariantCultureIgnoreCase)) + continue; + var fInfo = new FileInfo(path); + fileInfos.Add(fInfo); + } +} + +Console.WriteLine("Scanning projects folder for latest files"); + +filePaths = Directory.EnumerateFiles(Path.Combine(Directory.GetCurrentDirectory(), "../../../../projects")); + +if (filePaths.Any()) +{ + foreach (var path in filePaths) + { + var fInfo = new FileInfo(path); + fileInfos.Add(fInfo); + } +} + +fileInfos = fileInfos.OrderByDescending(f => f.CreationTimeUtc).Take(10).ToList(); + +var myRSS = new rss(); + +myRSS.version = 2.0m; + +myRSS.channel = new rssChannel +{ + title = "athene.gay entries", + description = "blog entries for athene.gay", + language = "en-GB", + link = "https://athene.gay", + item = new List() +}; + +foreach (var file in fileInfos) +{ + var item = new rssChannelItem() + { + title = Path.GetFileNameWithoutExtension(file.Name), + pubDate = file.CreationTimeUtc.ToString(), + }; + if (file.FullName.Contains("entries")) + { + item.link = "https://athene.gay/entries/" + Path.GetFileName(file.Name); + } else if (file.FullName.Contains("projects")) + { + item.link = "https://athene.gay/projects/" + Path.GetFileName(file.Name); + } + myRSS.channel.item.Add(item); +} + +var output = Generator.SerializeRSS(myRSS); + +var rssPath = Path.Combine(Directory.GetCurrentDirectory(), "../../../../feed.rss"); + +if (File.Exists(rssPath)) { + File.Delete(rssPath); +} + +File.WriteAllText(rssPath, output); \ No newline at end of file