-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8385ca9
commit 46c435c
Showing
1 changed file
with
19 additions
and
21 deletions.
There are no files selected for viewing
40 changes: 19 additions & 21 deletions
40
src/Pilgaard.Blog/Features/BlogPost/BlogPostComponent.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,64 @@ | ||
@page "/posts/{blogPostSeriesPathName}/{blogPostPathName}" | ||
|
||
<article class="blog-post"> | ||
|
||
<MudText Typo="Typo.h3" Color="Color.Secondary"> | ||
@BlogPostSeries.Title - Part @BlogPost.NumberInSeries | ||
@_blogPostSeries.Title - Part @_blogPost.NumberInSeries | ||
</MudText> | ||
|
||
<MudText Typo="Typo.h1" Color="Color.Tertiary"> | ||
@BlogPost.Title | ||
@_blogPost.Title | ||
</MudText> | ||
|
||
<hr class="mb-5"/> | ||
<MudDivider Class="mb-5"/> | ||
|
||
@BlogPostText | ||
|
||
<BlogPostNavigation CurrentBlogPost="BlogPost" BlogPostSeries="BlogPostSeries"/> | ||
<BlogPostNavigation CurrentBlogPost="_blogPost" BlogPostSeries="_blogPostSeries"/> | ||
|
||
</article> | ||
<MetadataComponent | ||
Title="@Title" | ||
Description="@BlogPost.Description" | ||
Tags="@Tags" /> | ||
<MetadataComponent Title="@Title" | ||
Description="@_blogPost.Description" | ||
Tags="@Tags" /> | ||
<PrismCodeBlockRenderer/> | ||
<GiscusComponent/> | ||
<GiscusComponent /> | ||
@code { | ||
[Parameter] | ||
public string? BlogPostSeriesPathName { get; set; } | ||
|
||
[Parameter] | ||
public string BlogPostPathName { get; set; } = null!; | ||
|
||
public BlogPost BlogPost { get; set; } = null!; | ||
public BlogPostSeries BlogPostSeries { get; set; } = null!; | ||
private BlogPost _blogPost = null!; | ||
private BlogPostSeries _blogPostSeries = null!; | ||
|
||
private string Title => $"{DefaultMetadata.Title} | {_blogPost.Title} | {_blogPostSeries.Title} - Part {_blogPost.NumberInSeries}"; | ||
|
||
private string Title => $"{DefaultMetadata.Title} | {BlogPost.Title} | {BlogPostSeries.Title} - Part {BlogPost.NumberInSeries}"; | ||
private string Tags => string.Join(", ", _blogPost.Tags, _blogPostSeries.Tags); | ||
|
||
private string Tags => string.Join(", ", BlogPost.Tags, BlogPostSeries.Tags); | ||
|
||
private MarkupString BlogPostText { get; set; } | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
var path = GetPagePath(); | ||
var text = await File.ReadAllTextAsync(path); | ||
BlogPostText = text.ToHtml(); | ||
|
||
await base.OnInitializedAsync(); | ||
} | ||
|
||
private string GetPagePath() | ||
{ | ||
BlogPostSeriesPathName ??= "general"; | ||
BlogPostSeries = BlogPostData.AllBlogPostSeries.First(series => series.PathName == BlogPostSeriesPathName); | ||
BlogPost = BlogPostSeries.BlogPosts.FirstOrDefault(blogPost => blogPost.PathName == BlogPostPathName)!; | ||
|
||
_blogPostSeries = BlogPostData.AllBlogPostSeries.First(series => series.PathName == BlogPostSeriesPathName); | ||
|
||
_blogPost = _blogPostSeries.BlogPosts.FirstOrDefault(blogPost => blogPost.PathName == BlogPostPathName)!; | ||
|
||
var pathPrefix = Path.Join(AppDomain.CurrentDomain.BaseDirectory, "Pages", "posts"); | ||
|
||
var path = BlogPostSeriesPathName is null | ||
? Path.Join(pathPrefix, BlogPostPathName + ".md") | ||
: Path.Join(pathPrefix, BlogPostSeriesPathName, BlogPostPathName + ".md"); | ||
|
||
return path; | ||
} | ||
} |