diff options
Diffstat (limited to 'back-end/src/FeedGenerator.cs')
-rw-r--r-- | back-end/src/FeedGenerator.cs | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/back-end/src/FeedGenerator.cs b/back-end/src/FeedGenerator.cs index 2aed945..ae8fd52 100644 --- a/back-end/src/FeedGenerator.cs +++ b/back-end/src/FeedGenerator.cs @@ -27,20 +27,27 @@ using System.Collections.Generic; using VNLib.Utils.IO; using VNLib.Plugins; +using VNLib.Plugins.Extensions.Loading; using Content.Publishing.Blog.Admin.Model; namespace Content.Publishing.Blog.Admin { + [ConfigurationName("rss_feed", Required = false)] internal sealed class FeedGenerator : IRssFeedGenerator { const int defaultMaxItems = 20; const string ITUNES_XML_ATTR = "http://www.itunes.com/dtds/podcast-1.0.dtd"; const string CONTENT_XML_ATTR = "http://purl.org/rss/1.0/modules/content/"; + const string PODCAST_INDEX_ATTR = "https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md"; + const string GENERATOR_NAME = "CMNext"; public FeedGenerator(PluginBase pbase) { } + public FeedGenerator(PluginBase pbase, IConfigScope config) + { } + public void BuildFeed(IChannelContext context, IEnumerable<PostMeta> posts, VnMemoryStream output) { _ = context.Feed ?? throw new ArgumentNullException(nameof(context.Feed)); @@ -66,7 +73,7 @@ namespace Content.Publishing.Blog.Admin writer.WriteAttributeString("version", "2.0"); writer.WriteAttributeString("xmlns", "itunes", null, ITUNES_XML_ATTR); writer.WriteAttributeString("xmlns", "content", null, CONTENT_XML_ATTR); - + writer.WriteAttributeString("xmlns", "podcast", null, PODCAST_INDEX_ATTR); //Channel element writer.WriteStartElement("channel"); @@ -94,6 +101,12 @@ namespace Content.Publishing.Blog.Admin { PrintExtendedProps(prop, writer); } + + //Add generator tag if not set by user + if(!context.Feed.ExtendedProperties.Any(static p => "generator".Equals(p.Name, StringComparison.OrdinalIgnoreCase))) + { + writer.WriteElementString("generator", GENERATOR_NAME); + } } //Author @@ -127,9 +140,25 @@ namespace Content.Publishing.Blog.Admin writer.WriteElementString("itunes", "author", null, post.Author); //Description is just the post summary - writer.WriteElementString("description", post.Summary); writer.WriteElementString("itunes", "summary", null, post.Summary); + //Allow an html description from the post meta itself + if (post.HtmlDescription != null) + { + writer.WriteStartElement("description"); + writer.WriteCData(post.HtmlDescription); + writer.WriteEndElement(); + + //Add content encoded tag + writer.WriteStartElement("content", "encoded", null); + writer.WriteCData(post.HtmlDescription); + writer.WriteEndElement(); + } + else + { + writer.WriteElementString("description", post.Summary); + } + //Time as iso string from unix seconds timestamp string pubDate = DateTimeOffset.FromUnixTimeSeconds(post.Created).ToString("R"); @@ -190,6 +219,10 @@ namespace Content.Publishing.Blog.Admin PrintExtendedProps(child, writer); } } + else if(prop.Value != null && prop.Value.StartsWith("<![CDATA", StringComparison.OrdinalIgnoreCase)) + { + writer.WriteCData(prop.Value); + } else { //Write the value |