using SmartFormat; namespace OliverBooth.Data.Blog; /// /// Represents a blog post. /// public sealed class BlogPost : IEquatable { /// /// Gets the ID of the author. /// /// The author ID. public int AuthorId { get; private set; } /// /// Gets or sets the body of the blog post. /// /// The body. public string Body { get; set; } = string.Empty; /// /// Gets or sets a value indicating whether comments are enabled for the blog post. /// /// 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. /// /// The ID. public int Id { get; private set; } /// /// Gets or sets a value indicating whether the blog post is a redirect. /// /// if the blog post is a redirect; otherwise, . public bool IsRedirect { get; set; } /// /// Gets or sets the date and time at which the blog post was published. /// /// The publish timestamp. public DateTimeOffset Published { get; set; } /// /// Gets or sets the redirect URL of the blog post. /// /// The redirect URL. public string? RedirectUrl { get; set; } /// /// Gets or sets the URL slug of the blog post. /// /// The URL slug. public string Slug { get; set; } = string.Empty; /// /// Gets or sets the title of the blog post. /// /// The title. public string Title { get; set; } = string.Empty; /// /// Gets or sets the date and time at which the blog post was updated. /// /// The update timestamp. public DateTimeOffset? Updated { get; set; } /// /// Gets or sets the legacy WordPress ID of the blog post. /// /// The legacy WordPress ID. public int? WordPressId { get; set; } /// /// Returns a value indicating whether two instances of are equal. /// /// The first instance of to compare. /// The second instance of to compare. /// /// if and are equal; otherwise, /// . /// public static bool operator ==(BlogPost? left, BlogPost? right) => Equals(left, right); /// /// Returns a value indicating whether two instances of are not equal. /// /// The first instance of to compare. /// The second instance of to compare. /// /// if and are not equal; otherwise, /// . /// public static bool operator !=(BlogPost? left, BlogPost? right) => !(left == right); /// /// Returns a value indicating whether this instance of is equal to another instance. /// /// An instance to compare with this instance. /// /// if is equal to this instance; otherwise, /// . /// public bool Equals(BlogPost? other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return Id == other.Id; } /// /// Returns a value indicating whether this instance is equal to a specified object. /// /// An object to compare with this instance. /// /// if is an instance of and equals the /// value of this instance; otherwise, . /// public override bool Equals(object? obj) { return ReferenceEquals(this, obj) || obj is BlogPost other && Equals(other); } /// /// 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}"; } /// /// Gets the hash code for this instance. /// /// The hash code. public override int GetHashCode() { // ReSharper disable once NonReadonlyMemberInGetHashCode return Id; } }