@page "/{slug:nonfile}" @implements IAsyncDisposable @inject IPostService PostService @inject NavigationManager NavigationManager @inject IJSRuntime JSRuntime @inject ILogger Logger @if (BlogPost is null) { return; } else { @BlogPost.Title - journal

@BlogPost.Title

@BlogPost.PublishedAt.ToString("MMMM d, yyyy")

@((MarkupString)BlogPost.Content)
} @code { [Parameter] public string Slug { get; set; } = string.Empty; private PostWithContent? BlogPost; private IJSObjectReference? module; protected override async Task OnInitializedAsync() { var post = await PostService.GetPostAsync(Slug); if (post is null) { NavigationManager.NavigateTo("/Error/404"); return; } BlogPost = post; } protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { module = await JSRuntime.InvokeAsync("import", "./Components/Pages/Post.razor.js"); await module.InvokeVoidAsync("addAnchors"); await module.InvokeVoidAsync("addClipboard"); } } async ValueTask IAsyncDisposable.DisposeAsync() { try { if (module is not null) { await module.DisposeAsync(); } } catch (Exception ex) when (ex is JSDisconnectedException) { } catch (Exception ex) { Logger.LogError(ex, "Error disposing of the module"); } } }