-
-
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.
Merge pull request #19 from NielsPilgaard/seo
Search Engine Optimizations
- Loading branch information
Showing
21 changed files
with
254 additions
and
126 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
src/Pilgaard.Blog/Components/BlogPostSeriesComponent.razor
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/Pilgaard.Blog/Models/BlogPost.cs → ...lgaard.Blog/Features/BlogPost/BlogPost.cs
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,4 +1,4 @@ | ||
namespace Pilgaard.Blog.Models; | ||
namespace Pilgaard.Blog.Features.BlogPost; | ||
|
||
public class BlogPost | ||
{ | ||
|
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<MudCard Style="width: 350px; height: 250px" Elevation="5"> | ||
<MudNavLink Style="height: 100%" Href="@BlogPostSeries.GetRelativePath(BlogPost)"> | ||
<MudCardHeader> | ||
<CardHeaderContent> | ||
<MudText Typo="Typo.subtitle1" Color="Color.Primary">Part @BlogPost.NumberInSeries</MudText> | ||
<MudText Typo="Typo.h5" Color="Color.Tertiary">@BlogPost.Title</MudText> | ||
</CardHeaderContent> | ||
</MudCardHeader> | ||
<MudCardContent Class="pt-0"> | ||
<MudText Typo="Typo.body1" Color="Color.Default">@BlogPost.Description</MudText> | ||
<MudText Typo="Typo.caption" Color="Color.Primary">@string.Join(" ", BlogPost.Tags.Union(BlogPostSeries.Tags).Select(tag => $"#{tag}"))</MudText> | ||
</MudCardContent> | ||
</MudNavLink> | ||
</MudCard> | ||
|
||
@code { | ||
[Parameter] | ||
public BlogPost BlogPost { get; set; } = null!; | ||
|
||
[Parameter] | ||
public BlogPostSeries BlogPostSeries { get; set; } = null!; | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
@page "/posts/{blogPostSeriesPathName}/{blogPostPathName}" | ||
<article class="blog-post"> | ||
@if (BlogPostSeries is not null) | ||
{ | ||
<h3>@BlogPostSeries.Title - Part @BlogPost.NumberInSeries</h3> | ||
<h1>@BlogPost.Title</h1> | ||
<hr /> | ||
<br /> | ||
} | ||
@BlogPostText | ||
</article> | ||
<MetadataComponent | ||
Title="@Title" | ||
Description="@BlogPost.Description" | ||
Tags="@Tags" /> | ||
<PrismCodeBlockRenderer/> | ||
<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; } | ||
|
||
private string Title => BlogPostSeries?.Title is null ? | ||
$"{DefaultMetadata.Title} | {BlogPost.Title}" : | ||
$"{DefaultMetadata.Title} | {BlogPost.Title} | {BlogPostSeries.Title} - Part {BlogPost.NumberInSeries}"; | ||
|
||
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.FirstOrDefault(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; | ||
|
||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Pilgaard.Blog.Features.BlogPost; | ||
|
||
public static class BlogPostExtensions | ||
{ | ||
public static string GetRelativePath(this BlogPostSeries blogPostSeries, BlogPost blogPost) | ||
{ | ||
return "posts/" + blogPostSeries.PathName + "/" + blogPost.PathName; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/Pilgaard.Blog/Models/BlogPostSeries.cs → ....Blog/Features/BlogPost/BlogPostSeries.cs
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,4 +1,4 @@ | ||
namespace Pilgaard.Blog.Models; | ||
namespace Pilgaard.Blog.Features.BlogPost; | ||
|
||
public class BlogPostSeries | ||
{ | ||
|
16 changes: 16 additions & 0 deletions
16
src/Pilgaard.Blog/Features/BlogPost/BlogPostSeriesComponent.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<div style="text-align: center"> | ||
<MudText Class="mt-8" Color="Color.Secondary" Typo="Typo.h3">@BlogPostSeries.Title</MudText> | ||
<MudDivider Class="mb-6" DividerType="DividerType.FullWidth"></MudDivider> | ||
<MudText Class="mb-6" Typo="Typo.h6">@BlogPostSeries.Description.ToHtml()</MudText> | ||
|
||
</div> | ||
<div class="d-flex flex-wrap gap-2 justify-center"> | ||
@foreach (var blogPost in BlogPostSeries.BlogPosts) | ||
{ | ||
<BlogPostCard BlogPost="@blogPost" BlogPostSeries="@BlogPostSeries"></BlogPostCard> | ||
} | ||
</div> | ||
@code { | ||
[Parameter] | ||
public BlogPostSeries BlogPostSeries { get; set; } = null!; | ||
} |
File renamed without changes.
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
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Pilgaard.Blog.Features.SEO; | ||
|
||
public static class DefaultMetadata | ||
{ | ||
public const string Title = "Pilgaard | dotnet blog"; | ||
public const string Description = "Hi! I write about code - Particularly C#, but also PowerShell and the occasional JavaScript."; | ||
public const string Tags = "blazor, dotnet, csharp, blog, programming"; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<PageTitle>@Title</PageTitle> | ||
<HeadContent> | ||
<meta name="description" content="@Description" /> | ||
<meta name="og:title" content="@Title" /> | ||
<meta name="og:description" content="@Description" /> | ||
|
||
@if (Tags is not null) | ||
{ | ||
<meta name="tags" content="@Tags" /> | ||
} | ||
</HeadContent> | ||
|
||
@code { | ||
[Parameter] | ||
public string Title { get; set; } = null!; | ||
|
||
[Parameter] | ||
public string Description { get; set; } = null!; | ||
|
||
[Parameter] | ||
public string? Tags { get; set; } // Comma separated list | ||
} |
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
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
Oops, something went wrong.