feat: display post tags

This commit is contained in:
Oliver Booth 2023-09-23 22:08:25 +01:00
parent 2ea52759b8
commit a9c4b3a144
Signed by: oliverbooth
GPG Key ID: E60B570D1B7557B5
8 changed files with 34 additions and 0 deletions

View File

@ -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"),

View File

@ -34,6 +34,9 @@ internal sealed class BlogPost : IBlogPost
/// <inheritdoc />
public string Slug { get; internal set; } = string.Empty;
/// <inheritdoc />
public IReadOnlyList<string> Tags { get; internal set; } = ArraySegment<string>.Empty;
/// <inheritdoc />
public string Title { get; internal set; } = string.Empty;

View File

@ -28,5 +28,10 @@ internal sealed class BlogPostConfiguration : IEntityTypeConfiguration<BlogPost>
builder.Property(e => e.DisqusPath).IsRequired(false);
builder.Property(e => e.Visibility).HasConversion(new EnumToStringConverter<BlogPostVisibility>()).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());
}
}

View File

@ -63,6 +63,12 @@ public interface IBlogPost
/// <value>The slug of the post.</value>
string Slug { get; }
/// <summary>
/// Gets the tags of the post.
/// </summary>
/// <value>The tags of the post.</value>
IReadOnlyList<string> Tags { get; }
/// <summary>
/// Gets the title of the post.
/// </summary>

View File

@ -64,6 +64,13 @@
<a href="#disqus_thread" data-disqus-identifier="@post.GetDisqusIdentifier()">0 Comments</a>
}
</p>
<div>
@foreach (string tag in post.Tags)
{
<a asp-page="Index" asp-route-tag="@tag" class="badge bg-secondary">@tag</a>
}
</div>
<hr>
<article data-blog-post="true" data-blog-id="@post.Id.ToString("D")">
<p class="text-center">Loading ...</p>

View File

@ -38,4 +38,9 @@
</p>
{{/if}}
</div>
<div class="card-footer">
{{#each post.tags}}
<a href="?tag={{this}}" class="badge text-bg-dark">{{this}}</a>
{{/each}}
</div>
</script>

View File

@ -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;

View File

@ -55,6 +55,7 @@ class UI {
enable_comments: post.commentsEnabled,
disqus_identifier: post.identifier,
trimmed: post.trimmed,
tags: post.tags
},
author: {
name: author.name,