add support for root sitemap.xml and robots.txt

This commit is contained in:
sbwalker 2023-12-12 14:50:08 -05:00
parent 9e0a4dfac8
commit e34b1b54d5

View File

@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Caching.Memory;
using Oqtane.Repository;
using Oqtane.Shared;
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
namespace Oqtane.Infrastructure
{
@ -60,6 +61,22 @@ namespace Oqtane.Infrastructure
context.Request.Path = path.Replace("/" + alias.Path, "");
}
}
// handle sitemap.xml root request (does not support subfolder aliases)
if (context.Request.Path.StartsWithSegments("/sitemap.xml"))
{
context.Request.Path = "/pages" + context.Request.Path;
}
// handle robots.txt root request (does not support subfolder aliases)
if (context.Request.Path.StartsWithSegments("/robots.txt"))
{
// allow all and specify site map
var robots = $"User-agent: *\n\nSitemap: {context.Request.Scheme}://{alias.Name}/pages/sitemap.xml";
context.Response.ContentType = "text/plain";
await context.Response.WriteAsync(robots);
return;
}
}
}