From a9c4b3a1447d47cf63b299d7839ef07fbdb3f5fc Mon Sep 17 00:00:00 2001
From: Oliver Booth
Date: Sat, 23 Sep 2023 22:08:25 +0100
Subject: [PATCH] feat: display post tags
---
OliverBooth/Controllers/Blog/BlogApiController.cs | 1 +
OliverBooth/Data/Blog/BlogPost.cs | 3 +++
.../Data/Blog/Configuration/BlogPostConfiguration.cs | 5 +++++
OliverBooth/Data/Blog/IBlogPost.cs | 6 ++++++
OliverBooth/Pages/Blog/Article.cshtml | 7 +++++++
OliverBooth/Pages/Blog/Index.cshtml | 5 +++++
src/ts/BlogPost.ts | 6 ++++++
src/ts/UI.ts | 1 +
8 files changed, 34 insertions(+)
diff --git a/OliverBooth/Controllers/Blog/BlogApiController.cs b/OliverBooth/Controllers/Blog/BlogApiController.cs
index 7065ae0..792186f 100644
--- a/OliverBooth/Controllers/Blog/BlogApiController.cs
+++ b/OliverBooth/Controllers/Blog/BlogApiController.cs
@@ -77,6 +77,7 @@ public sealed class BlogApiController : ControllerBase
excerpt = _blogPostService.RenderExcerpt(post, out bool trimmed),
content = includeContent ? _blogPostService.RenderPost(post) : null,
trimmed,
+ tags = post.Tags.Select(t => t.Replace(' ', '-')),
url = new
{
year = post.Published.ToString("yyyy"),
diff --git a/OliverBooth/Data/Blog/BlogPost.cs b/OliverBooth/Data/Blog/BlogPost.cs
index e1e1c3f..cfb1110 100644
--- a/OliverBooth/Data/Blog/BlogPost.cs
+++ b/OliverBooth/Data/Blog/BlogPost.cs
@@ -34,6 +34,9 @@ internal sealed class BlogPost : IBlogPost
///
public string Slug { get; internal set; } = string.Empty;
+ ///
+ public IReadOnlyList Tags { get; internal set; } = ArraySegment.Empty;
+
///
public string Title { get; internal set; } = string.Empty;
diff --git a/OliverBooth/Data/Blog/Configuration/BlogPostConfiguration.cs b/OliverBooth/Data/Blog/Configuration/BlogPostConfiguration.cs
index a248d96..7c89b2b 100644
--- a/OliverBooth/Data/Blog/Configuration/BlogPostConfiguration.cs
+++ b/OliverBooth/Data/Blog/Configuration/BlogPostConfiguration.cs
@@ -28,5 +28,10 @@ internal sealed class BlogPostConfiguration : IEntityTypeConfiguration
builder.Property(e => e.DisqusPath).IsRequired(false);
builder.Property(e => e.Visibility).HasConversion(new EnumToStringConverter()).IsRequired();
builder.Property(e => e.Password).HasMaxLength(255).IsRequired(false);
+ builder.Property(e => e.Tags).IsRequired()
+ .HasConversion(
+ tags => string.Join(' ', tags.Select(t => t.Replace(' ', '-'))),
+ tags => tags.Split(' ', StringSplitOptions.RemoveEmptyEntries)
+ .Select(t => t.Replace('-', ' ')).ToArray());
}
}
diff --git a/OliverBooth/Data/Blog/IBlogPost.cs b/OliverBooth/Data/Blog/IBlogPost.cs
index 6cf646a..a8b9818 100644
--- a/OliverBooth/Data/Blog/IBlogPost.cs
+++ b/OliverBooth/Data/Blog/IBlogPost.cs
@@ -63,6 +63,12 @@ public interface IBlogPost
/// The slug of the post.
string Slug { get; }
+ ///
+ /// Gets the tags of the post.
+ ///
+ /// The tags of the post.
+ IReadOnlyList Tags { get; }
+
///
/// Gets the title of the post.
///
diff --git a/OliverBooth/Pages/Blog/Article.cshtml b/OliverBooth/Pages/Blog/Article.cshtml
index 3432113..6907dd7 100644
--- a/OliverBooth/Pages/Blog/Article.cshtml
+++ b/OliverBooth/Pages/Blog/Article.cshtml
@@ -64,6 +64,13 @@
0 Comments
}
+
+ @foreach (string tag in post.Tags)
+ {
+
@tag
+ }
+
+
Loading ...
diff --git a/OliverBooth/Pages/Blog/Index.cshtml b/OliverBooth/Pages/Blog/Index.cshtml
index 75b6dd0..e5d36bd 100644
--- a/OliverBooth/Pages/Blog/Index.cshtml
+++ b/OliverBooth/Pages/Blog/Index.cshtml
@@ -38,4 +38,9 @@
{{/if}}
+
diff --git a/src/ts/BlogPost.ts b/src/ts/BlogPost.ts
index 4c4dac5..e57e689 100644
--- a/src/ts/BlogPost.ts
+++ b/src/ts/BlogPost.ts
@@ -14,6 +14,7 @@ class BlogPost {
private readonly _identifier: string;
private readonly _humanizedTimestamp: string;
private readonly _formattedDate: string;
+ private readonly _tags: string[];
constructor(json: any) {
this._id = json.id;
@@ -29,6 +30,7 @@ class BlogPost {
this._identifier = json.identifier;
this._humanizedTimestamp = json.humanizedTimestamp;
this._formattedDate = json.formattedDate;
+ this._tags = json.tags;
}
get id(): string {
@@ -66,6 +68,10 @@ class BlogPost {
get url(): BlogUrl {
return this._url;
}
+
+ get tags(): string[] {
+ return this._tags;
+ }
get trimmed(): boolean {
return this._trimmed;
diff --git a/src/ts/UI.ts b/src/ts/UI.ts
index 36f14e9..f5444f5 100644
--- a/src/ts/UI.ts
+++ b/src/ts/UI.ts
@@ -55,6 +55,7 @@ class UI {
enable_comments: post.commentsEnabled,
disqus_identifier: post.identifier,
trimmed: post.trimmed,
+ tags: post.tags
},
author: {
name: author.name,