Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement links for text-rendered WikiLinks (for YouTube) #1888

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions TASVideos/WikiModules/WikiLink.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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;

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; } = "";
Expand All @@ -21,7 +23,22 @@ public async Task<IViewComponentResult> InvokeAsync(string href, string? display
public async Task<string> RenderTextAsync(IWikiPage? pageData, string href, string? displayText, string? implicitDisplayText)
{
await GenerateLink(href, displayText, implicitDisplayText);
return DisplayText;
return $"{DisplayText} ( {AbsoluteUrl(Href)} )";
}

private 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)
Expand Down
Loading