Improved SEO by adding noindex header to non-parameterized RSS endpoints

This commit is contained in:
Mia Rose Winter 2024-03-17 13:30:28 +01:00
parent 31cec9327f
commit 3bf0f4e6df
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E

View file

@ -22,6 +22,9 @@ public class RssController(IOptions<Customization> customizations, ApplicationDb
public async Task<IActionResult> GetRssFeedAsync(string? category = null, Guid? author = null) { public async Task<IActionResult> GetRssFeedAsync(string? category = null, Guid? author = null) {
if (!Features.Value.Rss) return new JsonResult("RSS is disabled") {StatusCode = StatusCodes.Status401Unauthorized}; if (!Features.Value.Rss) return new JsonResult("RSS is disabled") {StatusCode = StatusCodes.Status401Unauthorized};
if (category is not null || author.HasValue)
Response.Headers.Append("x-robots-tag", "noindex");
var feed = await CreateFeedAll("RssFeed", category, author); var feed = await CreateFeedAll("RssFeed", category, author);
if (feed is null) return NotFound(); if (feed is null) return NotFound();
Response.ContentType = "application/atom+xml"; Response.ContentType = "application/atom+xml";
@ -33,6 +36,9 @@ public class RssController(IOptions<Customization> customizations, ApplicationDb
public async Task<IActionResult> GetAtomFeedAsync(string? category = null, Guid? author = null) { public async Task<IActionResult> GetAtomFeedAsync(string? category = null, Guid? author = null) {
if (!Features.Value.Rss) return new JsonResult("RSS is disabled") {StatusCode = StatusCodes.Status401Unauthorized}; if (!Features.Value.Rss) return new JsonResult("RSS is disabled") {StatusCode = StatusCodes.Status401Unauthorized};
if (category is not null || author.HasValue)
Response.Headers.Append("x-robots-tag", "noindex");
var feed = await CreateFeedAll("AtomFeed", category, author); var feed = await CreateFeedAll("AtomFeed", category, author);
if (feed is null) return NotFound(); if (feed is null) return NotFound();
Response.ContentType = "application/atom+xml"; Response.ContentType = "application/atom+xml";