Skip to content

Commit

Permalink
Docs: RSS feed for news and blogs (#5645)
Browse files Browse the repository at this point in the history
  • Loading branch information
stsrki authored Jul 25, 2024
1 parent 59a036a commit 703b618
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
26 changes: 26 additions & 0 deletions Documentation/Blazorise.Docs.Server/Infrastructure/SeoGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
Expand Down Expand Up @@ -61,6 +62,31 @@ from url in urls
await context.Response.WriteAsync( sitemap.ToString() );
}

public static async Task GenerateRssFeed( HttpContext context )
{
var baseUrl = GetBaseUrl( context );
var pages = Pages.News.Index.NewsEntries.Concat( Pages.Blog.Index.BlogEntries );

var sitemap = new XElement( "rss",
new XAttribute( XNamespace.Xmlns + "atom", "http://www.w3.org/2005/Atom" ),
new XAttribute( "version", "2.0" ),
new XElement( "channel",
new XElement( "title", "Blazorise News" ),
new XElement( "link", baseUrl ),
new XElement( "description", "Blazorise News Feed" ),
new XElement( "language", "en" ),
new XElement( "lastBuildDate", DateTime.UtcNow.ToString( "R" ) ),
from p in pages
orderby p.PostedOn descending
select new XElement( "item",
new XElement( "title", p.Text ),
new XElement( "link", $"{baseUrl}/{p.Url}" ),
new XElement( "description", p.Description ),
new XElement( "pubDate", DateTime.TryParse( p.PostedOn, CultureInfo.InvariantCulture, out var dt ) ? dt.ToString( "R" ) : null ) ) ) );

await context.Response.WriteAsync( sitemap.ToString() );
}

private static string GetBaseUrl( HttpContext context )
{
return $"{context.Request.Scheme}://{context.Request.Host.Value}{context.Request.PathBase.Value}";
Expand Down
1 change: 1 addition & 0 deletions Documentation/Blazorise.Docs.Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,6 @@ public void Configure( WebApplication app )
app.MapGet( "/robots.txt", SeoGenerator.GenerateRobots );
app.MapGet( "/sitemap.txt", SeoGenerator.GenerateSitemap );
app.MapGet( "/sitemap.xml", SeoGenerator.GenerateSitemapXml );
app.MapGet( "/feed.rss", SeoGenerator.GenerateRssFeed );
}
}
6 changes: 3 additions & 3 deletions Documentation/Blazorise.Docs/Pages/Blog/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</CardTitle>
</CardBody>
<CardBody Padding="Padding.Is0.OnY">
<BlogPagePostInto UserName="@pinnedBlog.AuthorName" ImageName="@pinnedBlog.AuthorImage" PostedOn="@pinnedBlog.PostedOn" Read="@pinnedBlog.ReadTime" />
<BlogPagePostInto UserName="@pinnedBlog.AuthorName" ImageName="@pinnedBlog.AuthorImage" PostedOn="@pinnedBlog.PostedOnFormatted" Read="@pinnedBlog.ReadTime" />
</CardBody>
</Card>
}
Expand All @@ -54,7 +54,7 @@
<BlogPageEntries Year="2022">
@foreach ( var item in BlogEntries.Where( x => ( ( selectedCategory == "All" || !string.IsNullOrEmpty( search ) ) || x.Category == selectedCategory ) && x.Text.Contains( search ?? string.Empty, StringComparison.InvariantCultureIgnoreCase ) ) )
{
<BlogPageEntriesItem @key="@item" To="@item.Url" ToText="@item.Text" ImageSource="@item.Image" AuthorName="@item.AuthorName" AuthorImage="@item.AuthorImage" PostedOn="@item.PostedOn" ReadTime="@item.ReadTime" />
<BlogPageEntriesItem @key="@item" To="@item.Url" ToText="@item.Text" ImageSource="@item.Image" AuthorName="@item.AuthorName" AuthorImage="@item.AuthorImage" PostedOn="@item.PostedOnFormatted" ReadTime="@item.ReadTime" />
}
</BlogPageEntries>

Expand All @@ -64,7 +64,7 @@
string search = "";
string selectedCategory = "All";

List<BlogEntry> BlogEntries = new List<BlogEntry>
public static List<BlogEntry> BlogEntries = new List<BlogEntry>
{
new BlogEntry { Category = "How To Guides", Url = "blog/how-to-create-social-media-share-buttons", Text = "How to create social media share buttons with Blazorise", Image = "img/blog/2024-05-17/how-to-create-social-media-share-buttons.png", AuthorName="Giorgi", AuthorImage="giorgi", PostedOn="2024-06-12", ReadTime="5 min" },
new BlogEntry { Category = "How To Guides", Url = "blog/how-to-implement-validation-with-captcha", Text = "How to implement validation with captcha", Image = "img/blog/2024-05-08/how-to-implement-validation-with-captcha.png", AuthorName="David Moreira", AuthorImage="david", PostedOn="2024-05-08", ReadTime="5 min", Pinned = true },
Expand Down
6 changes: 3 additions & 3 deletions Documentation/Blazorise.Docs/Pages/News/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</CardTitle>
</CardBody>
<CardBody Padding="Padding.Is0.OnY">
<NewsPagePostInfo UserName="@pinnedNews.AuthorName" ImageName="@pinnedNews.AuthorImage" PostedOn="@pinnedNews.PostedOn" Read="@pinnedNews.ReadTime" />
<NewsPagePostInfo UserName="@pinnedNews.AuthorName" ImageName="@pinnedNews.AuthorImage" PostedOn="@pinnedNews.PostedOnFormatted" Read="@pinnedNews.ReadTime" />
</CardBody>
</Card>
}
Expand All @@ -54,7 +54,7 @@
<NewsPageEntries Year="2022">
@foreach ( var item in NewsEntries.Where( x => ( ( selectedCategory == "All" || !string.IsNullOrEmpty( search ) ) || x.Category == selectedCategory ) && ( x.Text.Contains( search ?? string.Empty, StringComparison.InvariantCultureIgnoreCase ) || x.Description.Contains( search ?? string.Empty, StringComparison.InvariantCultureIgnoreCase ) ) ) )
{
<NewsPageEntriesItem @key="@item" To="@item.Url" ToText="@item.Text" ImageSource="@item.Image" AuthorName="@item.AuthorName" AuthorImage="@item.AuthorImage" PostedOn="@item.PostedOn" ReadTime="@item.ReadTime">
<NewsPageEntriesItem @key="@item" To="@item.Url" ToText="@item.Text" ImageSource="@item.Image" AuthorName="@item.AuthorName" AuthorImage="@item.AuthorImage" PostedOn="@item.PostedOnFormatted" ReadTime="@item.ReadTime">
@item.Description
</NewsPageEntriesItem>
}
Expand All @@ -66,7 +66,7 @@
string search = "";
string selectedCategory = "All";

List<BlogEntry> NewsEntries = new List<BlogEntry>
public static List<BlogEntry> NewsEntries = new List<BlogEntry>
{
new BlogEntry { Category = "Major releases", Url = "news/release-notes/160", Text = "Announcing Blazorise 1.6", Description = "Welcome to the July 2024 Blazorise 1.6 update! In this version, we are excited to bring you a host of new...", Image = "img/news/160/v160.png", AuthorName = "Mladen Macanović", AuthorImage = "mladen", PostedOn = "2024-07-23", ReadTime = "7 min", Pinned = true },
new BlogEntry { Category = "Maintenance", Url = "news/release-notes/153", Text = "Maintenance release: Blazorise 1.5.3", Description = "It's been a while, but we're excited to bring you the latest version of Blazorise! In version...", Image = "img/news/150/v153.png", AuthorName = "Mladen Macanović", AuthorImage = "mladen", PostedOn = "2024-06-03", ReadTime = "3 min" },
Expand Down
6 changes: 5 additions & 1 deletion Shared/Blazorise.Shared/Models/BlogEntry.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Blazorise.Shared.Models;
using System;
using System.Globalization;

namespace Blazorise.Shared.Models;

public class BlogEntry
{
Expand All @@ -12,4 +15,5 @@ public class BlogEntry
public string PostedOn { get; set; }
public string ReadTime { get; set; }
public bool Pinned { get; set; }
public string PostedOnFormatted => DateTime.TryParse( PostedOn, CultureInfo.InvariantCulture, out var dt ) ? dt.ToString( "MMMM dd, yyyy", CultureInfo.InvariantCulture ) : null;
}

0 comments on commit 703b618

Please sign in to comment.