diff --git a/OliverBooth/Data/Blog/BlogPost.cs b/OliverBooth/Data/Blog/BlogPost.cs index 5297521..3fc0ca4 100644 --- a/OliverBooth/Data/Blog/BlogPost.cs +++ b/OliverBooth/Data/Blog/BlogPost.cs @@ -1,4 +1,6 @@ -namespace OliverBooth.Data.Blog; +using SmartFormat; + +namespace OliverBooth.Data.Blog; /// /// Represents a blog post. @@ -23,6 +25,24 @@ public sealed class BlogPost : IEquatable /// if comments are enabled; otherwise, . public bool EnableComments { get; set; } = true; + /// + /// Gets or sets the base URL of the Disqus comments for the blog post. + /// + /// The Disqus base URL. + public string? DisqusDomain { get; set; } + + /// + /// Gets or sets the identifier of the Disqus comments for the blog post. + /// + /// The Disqus identifier. + public string? DisqusIdentifier { get; set; } + + /// + /// Gets or sets the URL path of the Disqus comments for the blog post. + /// + /// The Disqus URL path. + public string? DisqusPath { get; set; } + /// /// Gets the ID of the blog post. /// @@ -87,4 +107,37 @@ public sealed class BlogPost : IEquatable { return Id; } + + /// + /// Gets the Disqus identifier for the blog post. + /// + /// The Disqus identifier. + public string GetDisqusIdentifier() + { + return string.IsNullOrWhiteSpace(DisqusIdentifier) ? $"post-{Id}" : Smart.Format(DisqusIdentifier, this); + } + + /// + /// Gets the Disqus domain for the blog post. + /// + /// The Disqus domain. + public string GetDisqusDomain() + { + return string.IsNullOrWhiteSpace(DisqusDomain) + ? "https://oliverbooth.dev/blog" + : Smart.Format(DisqusDomain, this); + } + + /// + /// Gets the Disqus URL for the blog post. + /// + /// The Disqus URL. + public string GetDisqusUrl() + { + string path = string.IsNullOrWhiteSpace(DisqusPath) + ? $"{Published:yyyy/MM/dd}/{Slug}/" + : Smart.Format(DisqusPath, this); + + return $"{GetDisqusDomain()}/{path}"; + } } diff --git a/OliverBooth/Data/Blog/Configuration/BlogPostConfiguration.cs b/OliverBooth/Data/Blog/Configuration/BlogPostConfiguration.cs index c954273..10ebe86 100644 --- a/OliverBooth/Data/Blog/Configuration/BlogPostConfiguration.cs +++ b/OliverBooth/Data/Blog/Configuration/BlogPostConfiguration.cs @@ -25,5 +25,8 @@ internal sealed class BlogPostConfiguration : IEntityTypeConfiguration builder.Property(e => e.IsRedirect).IsRequired(); builder.Property(e => e.RedirectUrl).IsRequired(false); builder.Property(e => e.EnableComments).IsRequired(); + builder.Property(e => e.DisqusDomain).IsRequired(false); + builder.Property(e => e.DisqusIdentifier).IsRequired(false); + builder.Property(e => e.DisqusPath).IsRequired(false); } } diff --git a/OliverBooth/OliverBooth.csproj b/OliverBooth/OliverBooth.csproj index a567424..810a7a3 100644 --- a/OliverBooth/OliverBooth.csproj +++ b/OliverBooth/OliverBooth.csproj @@ -21,6 +21,7 @@ + diff --git a/OliverBooth/Pages/Blog/Article.cshtml b/OliverBooth/Pages/Blog/Article.cshtml index 1227679..f449615 100644 --- a/OliverBooth/Pages/Blog/Article.cshtml +++ b/OliverBooth/Pages/Blog/Article.cshtml @@ -1,4 +1,4 @@ -@page "/blog/{year:int}/{month:int}/{day:int}/{slug}" +@page "/blog/{year:int}/{month:int}/{day:int}/{slug}" @using Humanizer @model OliverBooth.Pages.Blog.Article @@ -7,13 +7,6 @@ return; } -@{ - bool isLegacyPost = Model.IsWordPressLegacyPost; - string disqusDomain = isLegacyPost ? "https://blog.oliverbooth.dev" : "https://oliverbooth.dev/blog"; - string disqusId = isLegacyPost ? $"{post.WordPressId} {disqusDomain}/?p={post.WordPressId}" : post.Id.ToString(); - var disqusUrl = $"{disqusDomain}/{post.Published:yyyy/MM/dd}/{post.Slug}/"; -} -