This repository has been archived by the owner on Dec 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.wyam
78 lines (71 loc) · 2.91 KB
/
config.wyam
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#recipe Blog
#theme SolidState
#n Microsoft.SyndicationFeed.ReaderWriter -v 1.0.2
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Xml;
using Microsoft.SyndicationFeed;
using Microsoft.SyndicationFeed.Rss;
using Microsoft.SyndicationFeed.Atom;
// Customize your settings and add new ones here
Settings[Keys.Host] = "devchatter.com";
Settings[BlogKeys.Title] = "DevChatter";
Settings[BlogKeys.Description] = "Welcome to DevChatter!";
Settings[BlogKeys.Image] = "/images/basic-banner.png";
Settings["LinkHideExtensions"] = false;
//Settings["Intro"] = "Where the dev chat never stops!";
// Add any pipeline customizations here
Pipelines.Add("VideoFeed",
new Execute((inputs, ctx, _) => GetFeedData.GetFeedDataWorker(inputs, ctx).Result),
//new Content((doc, ctx) => $"Title: { doc.String("Title") }, Description: { doc.String("Description") }"),
new Razor().WithLayout("_VideoLayout.cshtml"),
new WriteFiles((doc, ctx) =>
{
DateTime publishedDate = DateTime.Parse(doc.String("Published"));
return $"videos\\{publishedDate:yyyyMMdd}-{doc.String("Filename")}.html";
})
);
public class GetFeedData
{
public static async Task<IEnumerable<IDocument>>
GetFeedDataWorker(IReadOnlyList<IDocument> inputs,
IExecutionContext context)
{
const string feedUrl = "https://twitchrss.appspot.com/vod/devchatter";
var xmlReaderSettings = new XmlReaderSettings
{
Async = true,
DtdProcessing = DtdProcessing.Ignore
};
using (WebClient webClient = new WebClient())
using(var stream = await webClient.OpenReadTaskAsync(feedUrl))
using(StreamReader streamReader = new StreamReader(stream))
using(XmlReader xmlReader = XmlReader.Create(streamReader, xmlReaderSettings))
{
List<IDocument> outputs = new List<IDocument>();
xmlReader.MoveToContent();
Wyam.Common.Tracing.Trace.Information($"Read feed");
XmlFeedReader feedReader = new RssFeedReader(xmlReader);
while(await feedReader.Read())
{
if(feedReader.ElementType == SyndicationElementType.Item)
{
// Create a Wyam document from the RSS item
ISyndicationItem item = await feedReader.ReadItem();
IDocument doc = context.GetDocument(new MetadataItems
{
{ "Title", item.Title },
{ "Link", item.Links.FirstOrDefault(x => x.RelationshipType == RssLinkTypes.Alternate)?.Uri.ToString() ?? item.Id },
{ "Published", item.Published },
{ "Description", item.Description },
{ "Filename", item.Id }
});
outputs.Add(doc);
}
}
return outputs;
}
}
}