Skip to content

Commit d20bc86

Browse files
authored
Fix/font preload static path (#775)
* Acquire static prefix from the Model.
1 parent 307f253 commit d20bc86

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/Elastic.Markdown/Helpers/Preloader.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public static partial class FontPreloader
1313
{
1414
private static IReadOnlyCollection<string>? FontUriCache = null!;
1515

16-
public static async Task<IReadOnlyCollection<string>> GetFontUrisAsync() => FontUriCache ??= await LoadFontUrisAsync();
17-
private static async Task<IReadOnlyCollection<string>> LoadFontUrisAsync()
16+
public static async Task<IReadOnlyCollection<string>> GetFontUrisAsync(string? urlPrefix) => FontUriCache ??= await LoadFontUrisAsync(urlPrefix);
17+
private static async Task<IReadOnlyCollection<string>> LoadFontUrisAsync(string? urlPrefix)
1818
{
1919
var cachedFontUris = new List<string>();
2020
var assembly = Assembly.GetExecutingAssembly();
@@ -28,7 +28,7 @@ private static async Task<IReadOnlyCollection<string>> LoadFontUrisAsync()
2828
foreach (Match match in matches)
2929
{
3030
if (match.Success)
31-
cachedFontUris.Add($"/_static/{match.Groups[1].Value}");
31+
cachedFontUris.Add($"{urlPrefix}/_static/{match.Groups[1].Value}");
3232
}
3333
FontUriCache = cachedFontUris;
3434
return FontUriCache;

src/Elastic.Markdown/Slices/Layout/_Head.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@using Elastic.Markdown.Helpers
33
<head>
44
<title>@Model.Title</title>
5-
@foreach (var fontFile in await FontPreloader.GetFontUrisAsync())
5+
@foreach (var fontFile in await FontPreloader.GetFontUrisAsync(@Model.UrlPathPrefix))
66
{
77
<link rel="preload" href="@fontFile" as="font" type="font/woff2" crossorigin>
88
}

0 commit comments

Comments
 (0)