diff options
author | vnugent <public@vaughnnugent.com> | 2023-09-30 21:43:19 -0400 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2023-09-30 21:43:19 -0400 |
commit | 95d60952b3ea470495003b0d0e51840cd8e68605 (patch) | |
tree | 79f5179c4dd9349c7b88b7b1d2ed13b53152d166 /back-end | |
parent | 62da31eb31baf7e27bf4c6d3d15e2c69617e2f74 (diff) |
configure html podcast description support and minor ui tweaks
Diffstat (limited to 'back-end')
-rw-r--r-- | back-end/src/FeedGenerator.cs | 37 | ||||
-rw-r--r-- | back-end/src/Model/BlogPost.cs | 5 | ||||
-rw-r--r-- | back-end/src/Model/PostMeta.cs | 3 |
3 files changed, 43 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 diff --git a/back-end/src/Model/BlogPost.cs b/back-end/src/Model/BlogPost.cs index 0adea40..86cc289 100644 --- a/back-end/src/Model/BlogPost.cs +++ b/back-end/src/Model/BlogPost.cs @@ -44,6 +44,11 @@ namespace Content.Publishing.Blog.Admin.Model .IllegalCharacters() .MaximumLength(200); + //Allow an custom html description to be stored on the post object + validator.RuleFor(x => x.HtmlDescription) + .MaximumLength(4000) + .When(p => p.HtmlDescription != null); + validator.RuleFor(x => x.Author!) .NotEmpty() .IllegalCharacters() diff --git a/back-end/src/Model/PostMeta.cs b/back-end/src/Model/PostMeta.cs index 2bb963e..ce92c7e 100644 --- a/back-end/src/Model/PostMeta.cs +++ b/back-end/src/Model/PostMeta.cs @@ -43,6 +43,9 @@ namespace Content.Publishing.Blog.Admin.Model [JsonPropertyName("summary")] public string? Summary { get; set; } + [JsonPropertyName("html_description")] + public string? HtmlDescription { get; set; } + [JsonPropertyName("tags")] public string[]? Tags { get; set; } |