From 5a5711d57a32441384e867095adb9dd1c9d64326 Mon Sep 17 00:00:00 2001 From: Masterjun3 Date: Thu, 20 Jun 2024 01:45:50 +0200 Subject: [PATCH 1/2] implement links for text-rendered wikilinks (for youtube) --- TASVideos/WikiModules/WikiLink.cshtml.cs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/TASVideos/WikiModules/WikiLink.cshtml.cs b/TASVideos/WikiModules/WikiLink.cshtml.cs index 6ff3786f9..832be5d95 100644 --- a/TASVideos/WikiModules/WikiLink.cshtml.cs +++ b/TASVideos/WikiModules/WikiLink.cshtml.cs @@ -1,4 +1,6 @@ -using TASVideos.Core.Services.Wiki; +using Microsoft.Extensions.Hosting; +using TASVideos.Core.Services.Wiki; +using TASVideos.Core.Settings; using TASVideos.Data.Helpers; using TASVideos.WikiEngine; @@ -6,7 +8,7 @@ namespace TASVideos.WikiModules; [WikiModule(ModuleNames.WikiLink)] [TextModule] -public class WikiLink(ApplicationDbContext db) : WikiViewComponent +public class WikiLink(ApplicationDbContext db, AppSettings settings) : WikiViewComponent { public string Href { get; set; } = ""; public string DisplayText { get; set; } = ""; @@ -21,7 +23,22 @@ public async Task InvokeAsync(string href, string? display public async Task RenderTextAsync(IWikiPage? pageData, string href, string? displayText, string? implicitDisplayText) { await GenerateLink(href, displayText, implicitDisplayText); - return DisplayText; + return $"{DisplayText} ( {AbsoluteUrl(Href)} )"; + } + + public string AbsoluteUrl(string url) + { + if (!Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out var parsed)) + { + return url; + } + + if (!parsed.IsAbsoluteUri) + { + return $"{settings.BaseUrl}/{url.TrimStart('/')}"; + } + + return url; } private async Task GenerateLink(string href, string? displayText, string? implicitDisplayText) From a39d269309bd078ea2c68cdcb4f9662730df14a2 Mon Sep 17 00:00:00 2001 From: Masterjun3 Date: Thu, 20 Jun 2024 01:49:31 +0200 Subject: [PATCH 2/2] this method was meant to be private --- TASVideos/WikiModules/WikiLink.cshtml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TASVideos/WikiModules/WikiLink.cshtml.cs b/TASVideos/WikiModules/WikiLink.cshtml.cs index 832be5d95..0aefce9ba 100644 --- a/TASVideos/WikiModules/WikiLink.cshtml.cs +++ b/TASVideos/WikiModules/WikiLink.cshtml.cs @@ -26,7 +26,7 @@ public async Task RenderTextAsync(IWikiPage? pageData, string href, stri return $"{DisplayText} ( {AbsoluteUrl(Href)} )"; } - public string AbsoluteUrl(string url) + private string AbsoluteUrl(string url) { if (!Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out var parsed)) {