diff --git a/src/Blog/Components/Pages/Error.razor b/src/Blog/Components/Pages/Error.razor index f89d2ae..1d6dd34 100644 --- a/src/Blog/Components/Pages/Error.razor +++ b/src/Blog/Components/Pages/Error.razor @@ -1,7 +1,12 @@ @page "/Error" @using System.Diagnostics -Error +@PageTitle + + + + +

Error

@@ -19,9 +24,10 @@ { [CascadingParameter] private HttpContext? HttpContext { get; set; } - private string? RequestId { get; set; } private bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + private const string PageTitle = "Error - journal"; + private const string Description = "An unhandled error occurred while processing your request."; protected override void OnInitialized() => RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier; diff --git a/src/Blog/Components/Pages/Home.razor b/src/Blog/Components/Pages/Home.razor index 6cd10d5..29b2dda 100644 --- a/src/Blog/Components/Pages/Home.razor +++ b/src/Blog/Components/Pages/Home.razor @@ -1,10 +1,17 @@ @page "/" -journal - A blog by Stevan Freeborn +@PageTitle - + +

Posts

- \ No newline at end of file + + +@code +{ + private const string PageTitle = "journal - A blog by Stevan Freeborn"; + private const string Description = "A blog by Stevan Freeborn"; +} \ No newline at end of file diff --git a/src/Blog/Components/Pages/Post.razor b/src/Blog/Components/Pages/Post.razor index 1628c12..1f939ef 100644 --- a/src/Blog/Components/Pages/Post.razor +++ b/src/Blog/Components/Pages/Post.razor @@ -10,12 +10,19 @@ } else { - @BlogPost.Title - journal + var title = $"{BlogPost.Title} - journal"; + var description = BlogPost.Lead; - + @title - + + @@ -29,6 +36,8 @@ else @((MarkupString)BlogPost.Content)
+ + } @code diff --git a/src/Blog/Components/Pages/Privacy.razor b/src/Blog/Components/Pages/Privacy.razor index 2eaf4b3..f162b73 100644 --- a/src/Blog/Components/Pages/Privacy.razor +++ b/src/Blog/Components/Pages/Privacy.razor @@ -1,5 +1,12 @@ @page "/privacy" +@PageTitle + + + + + +

Privacy Policy for journal

@@ -112,4 +119,10 @@

By using our website, you hereby consent to our Privacy Policy and agree to its Terms and Conditions.

-
\ No newline at end of file + + +@code +{ + private const string PageTitle = "Privacy Policy - journal"; + private const string Description = "Privacy Policy for journal"; +} \ No newline at end of file diff --git a/src/Blog/Components/Pages/Terms.razor b/src/Blog/Components/Pages/Terms.razor index 42dc04d..4bac4b3 100644 --- a/src/Blog/Components/Pages/Terms.razor +++ b/src/Blog/Components/Pages/Terms.razor @@ -1,5 +1,12 @@ @page "/terms" +@PageTitle + + + + + +

Terms and Conditions

@@ -266,4 +273,10 @@ liable for any loss or damage of any nature.

-
\ No newline at end of file + + +@code +{ + private const string PageTitle = "Terms and Conditions - journal"; + private const string Description = "Terms and Conditions for journal"; +} \ No newline at end of file diff --git a/src/Blog/Components/Pages/_Error404.razor b/src/Blog/Components/Pages/_Error404.razor index 17a7d91..c9026f2 100644 --- a/src/Blog/Components/Pages/_Error404.razor +++ b/src/Blog/Components/Pages/_Error404.razor @@ -1,8 +1,22 @@ @page "/Error/404" +@PageTitle + + + + + +

Not Found

Hmm...it doesn't look like the page you were looking for exists, but we did find this adorable corgi.

- A cute corgi -
\ No newline at end of file + A cute corgi + + +@code +{ + private const string PageTitle = "Not Found - journal"; + private const string Description = "We couldn't find the page you were looking for. Here's a cute corgi instead."; + private const string Image = "not-found-corgi.jpg"; +} \ No newline at end of file diff --git a/src/Blog/Components/Utils/OpenGraph.razor b/src/Blog/Components/Utils/OpenGraph.razor new file mode 100644 index 0000000..e5a622f --- /dev/null +++ b/src/Blog/Components/Utils/OpenGraph.razor @@ -0,0 +1,40 @@ +@namespace Blog.Components.Utils +@inject IHttpContextAccessor HttpContextAccessor + + + + + + + +@code +{ + [Parameter] + public string PageTitle { get; set; } = "journal - A blog by Stevan Freeborn"; + + [Parameter] + public string Description { get; set; } = "A blog by Stevan Freeborn"; + + [Parameter] + public string Type { get; set; } = "website"; + + [Parameter] + public string Image { get; set; } = string.Empty; + + private string BaseUrl { get; set; } = string.Empty; + private string OpenGraphUrl { get; set; } = string.Empty; + private string OpenGraphImage => string.IsNullOrWhiteSpace(Image) + ? $"{BaseUrl}/site-og.png" + : $"{BaseUrl}/{Image}"; + + protected override void OnInitialized() + { + if (HttpContextAccessor.HttpContext is null) { + Console.WriteLine("HttpContext is null"); + return; + } + + BaseUrl = $"{HttpContextAccessor.HttpContext.Request.Scheme}://{HttpContextAccessor.HttpContext.Request.Host}"; + OpenGraphUrl = $"{BaseUrl}{HttpContextAccessor.HttpContext.Request.Path}"; + } +} \ No newline at end of file diff --git a/src/Blog/Posts/Post.cs b/src/Blog/Posts/Post.cs index fe170b6..64ccda8 100644 --- a/src/Blog/Posts/Post.cs +++ b/src/Blog/Posts/Post.cs @@ -7,6 +7,7 @@ record Post public bool IsPublished { get; init; } = false; public DateTime PublishedAt { get; init; } public string Slug { get; init; } = string.Empty; + public string OpenGraphImage { get; init; } = string.Empty; } record PostWithContent : Post diff --git a/src/Blog/Program.cs b/src/Blog/Program.cs index 74e4259..86a62db 100644 --- a/src/Blog/Program.cs +++ b/src/Blog/Program.cs @@ -4,6 +4,7 @@ builder.Services.ConfigureOptions(); builder.Services.AddSingleton(); builder.Services.AddScoped(); +builder.Services.AddHttpContextAccessor(); builder.Services.AddRazorComponents(); var app = builder.Build(); diff --git a/src/Blog/wwwroot/favicon.ico b/src/Blog/wwwroot/favicon.ico index 794347d..4c4e5b4 100644 Binary files a/src/Blog/wwwroot/favicon.ico and b/src/Blog/wwwroot/favicon.ico differ diff --git a/src/Blog/wwwroot/posts/test-blog/index.md b/src/Blog/wwwroot/posts/test-blog/index.md index f489dac..7e34c46 100644 --- a/src/Blog/wwwroot/posts/test-blog/index.md +++ b/src/Blog/wwwroot/posts/test-blog/index.md @@ -3,7 +3,8 @@ "title": "Test Blog", "lead": "This is a test blog post.", "isPublished": true, - "publishedAt": "2024-04-10" + "publishedAt": "2024-04-10", + "openGraphImage": "posts/test-blog/og-image.png", } ``` @@ -46,6 +47,8 @@ Here are some examples of text formatting: ![Cute Dog](https://placedog.net/672?random) +![The Office Gif](posts/test-blog/the-office.gif) + ## Blockquotes > Markdown is a lightweight markup language with plain-text formatting syntax. diff --git a/src/Blog/wwwroot/posts/test-blog/og-image.png b/src/Blog/wwwroot/posts/test-blog/og-image.png new file mode 100644 index 0000000..fb95c50 Binary files /dev/null and b/src/Blog/wwwroot/posts/test-blog/og-image.png differ diff --git a/src/Blog/wwwroot/posts/test-blog/the-office.gif b/src/Blog/wwwroot/posts/test-blog/the-office.gif new file mode 100644 index 0000000..cb7a201 Binary files /dev/null and b/src/Blog/wwwroot/posts/test-blog/the-office.gif differ diff --git a/src/Blog/wwwroot/site-og.png b/src/Blog/wwwroot/site-og.png new file mode 100644 index 0000000..ada169d Binary files /dev/null and b/src/Blog/wwwroot/site-og.png differ