Fix: Many SVG assets were not showing properly if rootpath is used

This commit is contained in:
nicolas.dorier 2021-10-25 14:55:58 +09:00
parent fb1fcbe0b9
commit 26bcdbc766
No known key found for this signature in database
GPG key ID: 6618763EF09186FE

View file

@ -4,6 +4,7 @@ using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BTCPayServer.Configuration;
using BTCPayServer.Security;
using BTCPayServer.Services;
using Microsoft.AspNetCore.Razor.TagHelpers;
@ -141,4 +142,25 @@ namespace BTCPayServer.TagHelpers
}
}
}
// Make sure that <svg><use href=/ are correctly working if rootpath is present
[HtmlTargetElement("use", Attributes = "href")]
public class SVGUse : TagHelper
{
private string _RootPath;
public SVGUse(BTCPayServerOptions opts)
{
_RootPath = opts.RootPath;
}
public override void Process(TagHelperContext context, TagHelperOutput output)
{
if (string.IsNullOrEmpty(_RootPath) || _RootPath == "/")
return;
var attr = output.Attributes["href"];
if (!attr.Value.ToString().StartsWith("/", StringComparison.OrdinalIgnoreCase))
return;
output.Attributes.SetAttribute("href", $"{_RootPath}{attr.Value}");
}
}
}