]> fortfriendship.online Git - gnargle.github.io.git/blob - RSSGen/Program.cs
add ada's dreamwidth to links
[gnargle.github.io.git] / RSSGen / Program.cs
1 using OpenGraphNet;
2 using RssFeedGenerator;
3 using System;
4 using System.Collections.Generic;
5 using System.IO;
6 using System.Runtime.InteropServices;
7
8 // See https://aka.ms/new-console-template for more information
9 Console.WriteLine("Scanning entries folder for latest files");
10
11 var folder = String.Empty;
12
13 if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
14 {
15 folder = Path.Combine(Directory.GetCurrentDirectory(), "../entries");
16 }
17 else
18 {
19 folder = Path.Combine(Directory.GetCurrentDirectory(), "../../../../entries");
20 }
21 var filePaths = Directory.EnumerateFiles(folder);
22 var fileInfos = new List<FileInfo>();
23
24 if (filePaths.Any())
25 {
26 foreach (var path in filePaths)
27 {
28 if (Path.GetFileNameWithoutExtension(path).Equals("template", StringComparison.InvariantCultureIgnoreCase))
29 continue;
30 var fInfo = new FileInfo(path);
31 fileInfos.Add(fInfo);
32 }
33 }
34
35 Console.WriteLine("Scanning projects folder for latest files");
36
37 if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
38 {
39 folder = Path.Combine(Directory.GetCurrentDirectory(), "../projects");
40 }
41 else
42 {
43 folder = Path.Combine(Directory.GetCurrentDirectory(), "../../../../projects");
44 }
45
46 filePaths = Directory.EnumerateFiles(folder);
47
48 if (filePaths.Any())
49 {
50 foreach (var path in filePaths)
51 {
52 var fInfo = new FileInfo(path);
53 fileInfos.Add(fInfo);
54 }
55 }
56
57 fileInfos = fileInfos.OrderByDescending(f => f.CreationTimeUtc).Take(10).ToList();
58
59 var myRSS = new rss();
60
61 myRSS.version = 2.0m;
62
63 myRSS.channel = new rssChannel
64 {
65 title = "athene.gay entries",
66 description = "blog entries for athene.gay",
67 language = "en-GB",
68 link = "https://athene.gay",
69 item = new List<rssChannelItem>(),
70 link1 = new link
71 {
72 href = "https://athene.gay/feed.xml",
73 rel = "self",
74 type = "application/rss+xml",
75 }
76 };
77
78 foreach (var file in fileInfos)
79 {
80 var htmlString = File.ReadAllText(file.FullName);
81 OpenGraph graph = OpenGraph.ParseHtml(htmlString);
82 var publishDate = DateTime.Parse(graph.Metadata["article:published_time"].First());
83 var item = new rssChannelItem()
84 {
85 title = graph.Title,
86 description = graph.Metadata["og:description"].First(),
87 pubDate = publishDate.ToString("r"),
88 };
89 if (file.FullName.Contains("entries"))
90 {
91 item.link = "https://athene.gay/entries/" + Path.GetFileName(file.Name);
92 }
93 else if (file.FullName.Contains("projects"))
94 {
95 item.link = "https://athene.gay/projects/" + Path.GetFileName(file.Name);
96 }
97 item.guid = new rssChannelItemGuid()
98 {
99 isPermaLink = true,
100 Value = item.link
101 };
102 myRSS.channel.item.Add(item);
103 }
104
105 var output = Generator.SerializeRSS(myRSS);
106
107 var rssPath = String.Empty;
108
109 if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
110 {
111 rssPath = Path.Combine(Directory.GetCurrentDirectory(), "../feed.xml");
112 }
113 else
114 {
115 rssPath = Path.Combine(Directory.GetCurrentDirectory(), "../../../../feed.xml");
116 }
117
118 if (File.Exists(rssPath))
119 {
120 File.Delete(rssPath);
121 }
122
123 Console.WriteLine("RSS generated, outputting to console and file");
124 Console.WriteLine(output);
125
126 File.WriteAllText(rssPath, output);