diff --git a/scripts/deploy.ps1 b/scripts/deploy.ps1 index 61d2341..d85fc07 100644 --- a/scripts/deploy.ps1 +++ b/scripts/deploy.ps1 @@ -1,6 +1,7 @@ $NGINX_CONFIG_PATH = "/etc/nginx/sites-available/blog.stevanfreeborn.com" -function StartContainer { +function StartContainer +{ param ( [string]$containerColor, [string]$dockerTag @@ -56,7 +57,8 @@ function StartContainer { return $containerHostPort } -function UpdateNginxConfig { +function UpdateNginxConfig +{ param ( [string]$filePath, [string]$portNumber diff --git a/src/Blog/Components/App.razor b/src/Blog/Components/App.razor index e9fabe7..1dc87a3 100644 --- a/src/Blog/Components/App.razor +++ b/src/Blog/Components/App.razor @@ -16,7 +16,6 @@ -
@@ -29,6 +37,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/appsettings.example.json b/src/Blog/appsettings.example.json index a731b84..33ba1f0 100644 --- a/src/Blog/appsettings.example.json +++ b/src/Blog/appsettings.example.json @@ -10,6 +10,5 @@ "FilePostServiceOptions": { "PostsDirectory": "wwwroot/posts" }, - "DetailedErrors": "true", - "GoogleAnalyticsTag": "" + "DetailedErrors": "true" } \ No newline at end of file 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