Skip to content

Commit

Permalink
Remove FeedBurner and just serve RSS feed directly
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel15 committed Mar 31, 2024
1 parent 8170e12 commit 4ce3cdf
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 43 deletions.
10 changes: 0 additions & 10 deletions Daniel15.Web/Configuration/ISiteConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ namespace Daniel15.Web.Configuration
/// </summary>
public interface ISiteConfiguration
{
/// <summary>
/// Gets the Google Analytics account to use for the site
/// </summary>
string GoogleAnalyticsAccount { get; }

/// <summary>
/// Gets the name of the blog
/// </summary>
Expand All @@ -20,11 +15,6 @@ public interface ISiteConfiguration
/// </summary>
string BlogDescription { get; }

/// <summary>
/// Gets the FeedBurner URL for the blog feed
/// </summary>
string FeedBurnerUrl { get; }

/// <summary>
/// Gets the Disqus shortname used by the blog comments
/// </summary>
Expand Down
10 changes: 0 additions & 10 deletions Daniel15.Web/Configuration/SiteConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ namespace Daniel15.Web.Configuration
/// </summary>
public class SiteConfiguration : ISiteConfiguration
{
/// <summary>
/// Gets the Google Analytics account to use for the site
/// </summary>
public string GoogleAnalyticsAccount { get; set; }

/// <summary>
/// Gets the name of the blog
/// </summary>
Expand All @@ -21,11 +16,6 @@ public class SiteConfiguration : ISiteConfiguration
/// </summary>
public string BlogDescription { get; set; }

/// <summary>
/// Gets the FeedBurner URL for the blog feed
/// </summary>
public string FeedBurnerUrl { get; set; }

/// <summary>
/// Gets the Disqus shortname used by the blog comments
/// </summary>
Expand Down
9 changes: 5 additions & 4 deletions Daniel15.Web/Controllers/FeedController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Daniel15.Web.ViewModels.Blog;
using Daniel15.Web.ViewModels.Feed;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OutputCaching;

namespace Daniel15.Web.Controllers
{
Expand Down Expand Up @@ -45,6 +46,7 @@ public FeedController(IBlogRepository blogRepository, IProjectRepository project
/// </summary>
/// <returns>Sitemap XML</returns>
[Route("sitemap.xml")]
[OutputCache]
public virtual ActionResult Sitemap()
{
var view = View(new SitemapViewModel
Expand All @@ -63,18 +65,16 @@ public virtual ActionResult Sitemap()
/// </summary>
/// <returns>RSS feed</returns>
[Route("blog/feed")]
[OutputCache]
public virtual ActionResult BlogLatest()
{
if (Request.ShouldRedirectToFeedburner())
return Redirect(_siteConfig.FeedBurnerUrl);

var posts = _blogRepository.LatestPosts(ITEMS_IN_FEED);
return RenderFeed(posts, new FeedViewModel
{
FeedGuidBase = "Latest",
Title = _siteConfig.BlogName,
Description = _siteConfig.BlogDescription,
FeedUrl = _siteConfig.FeedBurnerUrl,
FeedUrl = Url.Absolute(Url.Action("BlogLatest")),
SiteUrl = Url.Action("Index", "Blog", null, Request.Scheme),
});
}
Expand All @@ -87,6 +87,7 @@ public virtual ActionResult BlogLatest()
/// <returns>RSS feed</returns>
[Route("category/{parentSlug}/{slug}.rss", Order = 1, Name = "BlogSubCategoryFeed")]
[Route("category/{slug}.rss", Order = 2, Name = "BlogCategoryFeed")]
[OutputCache]
public virtual ActionResult BlogCategory(string slug, string parentSlug = null)
{
CategoryModel category;
Expand Down
18 changes: 0 additions & 18 deletions Daniel15.Web/Extensions/HttpRequestExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,6 @@ namespace Daniel15.Web.Extensions
/// </summary>
public static class HttpRequestExtensions
{
/// <summary>
/// Determines if the specified request should redirect to FeedBurner. This is the case when
/// a user accesses an RSS feed directly. Allows explicit access to the feed by adding a
/// feedburner_override GET parameter.
/// </summary>
/// <param name="request">The request</param>
/// <returns><c>true</c> if this request can redirect to FeedBurner</returns>
public static bool ShouldRedirectToFeedburner(this HttpRequest request)
{
var userAgent = request.Headers["User-Agent"].Count > 0
? request.Headers["User-Agent"][0].ToLower()
: string.Empty;
return
!userAgent.Contains("feedburner")
&& !userAgent.Contains("feedvalidator")
&& !request.Query.ContainsKey("feedburner_override");
}

/// <summary>
/// Send a GET to the sepecified URI and return the response body as a JArray (dynamic
/// JSON array)
Expand Down
5 changes: 5 additions & 0 deletions Daniel15.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
var services = builder.Services;
var config = builder.Configuration;
services.AddControllersWithViews();
services.AddOutputCache(options =>
{
options.AddBasePolicy(x => x.Expire(TimeSpan.FromHours(1)));
});
services.AddIdentity<SimpleIdentityUser, SimpleIdentityRole>()
.AddSimpleIdentity<SimpleIdentityUser>(config.GetSection("Auth"))
.AddDefaultTokenProviders();
Expand Down Expand Up @@ -134,6 +138,7 @@
// All real routes are defined using attributes.
app.UseRouting();
app.UseAuthorization();
app.UseOutputCache();
app.MapControllers();

app.Services.UseScheduler(scheduler =>
Expand Down
2 changes: 1 addition & 1 deletion Daniel15.Web/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<!-- Other stuff -->
<link rel="start" href="/" title="Home" />
<link rel="alternate" type="application/rss+xml" title="@Config.BlogName - RSS Feed" href="@Config.FeedBurnerUrl" />
<link rel="alternate" type="application/rss+xml" title="@Config.BlogName - RSS Feed" href="@Url.Absolute(Url.Action("BlogLatest", "Feed"))" />
<script>
document.documentElement.className = document.documentElement.className.replace('no-js', 'js');
</script>
Expand Down
17 changes: 17 additions & 0 deletions Daniel15.Web/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,20 @@ server {
# Override PHP 404 page
fastcgi_intercept_errors on;
}

# Redirect old Feedburner URLs
server {
server_name feeds.d15.biz feeds.dan.cx;
listen 80;
listen 443 ssl http2;
ssl_certificate /etc/letsencrypt/live/dan.cx/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/dan.cx/privkey.pem;

location / {
return 302 https://d.sb/;
}

location /daniel15 {
return 301 https://d.sb/blog/feed;
}
}

0 comments on commit 4ce3cdf

Please sign in to comment.