feat: display post tags
This commit is contained in:
parent
2ea52759b8
commit
a9c4b3a144
@ -77,6 +77,7 @@ public sealed class BlogApiController : ControllerBase
|
|||||||
excerpt = _blogPostService.RenderExcerpt(post, out bool trimmed),
|
excerpt = _blogPostService.RenderExcerpt(post, out bool trimmed),
|
||||||
content = includeContent ? _blogPostService.RenderPost(post) : null,
|
content = includeContent ? _blogPostService.RenderPost(post) : null,
|
||||||
trimmed,
|
trimmed,
|
||||||
|
tags = post.Tags.Select(t => t.Replace(' ', '-')),
|
||||||
url = new
|
url = new
|
||||||
{
|
{
|
||||||
year = post.Published.ToString("yyyy"),
|
year = post.Published.ToString("yyyy"),
|
||||||
|
@ -34,6 +34,9 @@ internal sealed class BlogPost : IBlogPost
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string Slug { get; internal set; } = string.Empty;
|
public string Slug { get; internal set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IReadOnlyList<string> Tags { get; internal set; } = ArraySegment<string>.Empty;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string Title { get; internal set; } = string.Empty;
|
public string Title { get; internal set; } = string.Empty;
|
||||||
|
|
||||||
|
@ -28,5 +28,10 @@ internal sealed class BlogPostConfiguration : IEntityTypeConfiguration<BlogPost>
|
|||||||
builder.Property(e => e.DisqusPath).IsRequired(false);
|
builder.Property(e => e.DisqusPath).IsRequired(false);
|
||||||
builder.Property(e => e.Visibility).HasConversion(new EnumToStringConverter<BlogPostVisibility>()).IsRequired();
|
builder.Property(e => e.Visibility).HasConversion(new EnumToStringConverter<BlogPostVisibility>()).IsRequired();
|
||||||
builder.Property(e => e.Password).HasMaxLength(255).IsRequired(false);
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,12 @@ public interface IBlogPost
|
|||||||
/// <value>The slug of the post.</value>
|
/// <value>The slug of the post.</value>
|
||||||
string Slug { get; }
|
string Slug { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the tags of the post.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The tags of the post.</value>
|
||||||
|
IReadOnlyList<string> Tags { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the title of the post.
|
/// Gets the title of the post.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -64,6 +64,13 @@
|
|||||||
<a href="#disqus_thread" data-disqus-identifier="@post.GetDisqusIdentifier()">0 Comments</a>
|
<a href="#disqus_thread" data-disqus-identifier="@post.GetDisqusIdentifier()">0 Comments</a>
|
||||||
}
|
}
|
||||||
</p>
|
</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")">
|
<article data-blog-post="true" data-blog-id="@post.Id.ToString("D")">
|
||||||
<p class="text-center">Loading ...</p>
|
<p class="text-center">Loading ...</p>
|
||||||
|
@ -38,4 +38,9 @@
|
|||||||
</p>
|
</p>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="card-footer">
|
||||||
|
{{#each post.tags}}
|
||||||
|
<a href="?tag={{this}}" class="badge text-bg-dark">{{this}}</a>
|
||||||
|
{{/each}}
|
||||||
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
@ -14,6 +14,7 @@ class BlogPost {
|
|||||||
private readonly _identifier: string;
|
private readonly _identifier: string;
|
||||||
private readonly _humanizedTimestamp: string;
|
private readonly _humanizedTimestamp: string;
|
||||||
private readonly _formattedDate: string;
|
private readonly _formattedDate: string;
|
||||||
|
private readonly _tags: string[];
|
||||||
|
|
||||||
constructor(json: any) {
|
constructor(json: any) {
|
||||||
this._id = json.id;
|
this._id = json.id;
|
||||||
@ -29,6 +30,7 @@ class BlogPost {
|
|||||||
this._identifier = json.identifier;
|
this._identifier = json.identifier;
|
||||||
this._humanizedTimestamp = json.humanizedTimestamp;
|
this._humanizedTimestamp = json.humanizedTimestamp;
|
||||||
this._formattedDate = json.formattedDate;
|
this._formattedDate = json.formattedDate;
|
||||||
|
this._tags = json.tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
get id(): string {
|
get id(): string {
|
||||||
@ -66,6 +68,10 @@ class BlogPost {
|
|||||||
get url(): BlogUrl {
|
get url(): BlogUrl {
|
||||||
return this._url;
|
return this._url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get tags(): string[] {
|
||||||
|
return this._tags;
|
||||||
|
}
|
||||||
|
|
||||||
get trimmed(): boolean {
|
get trimmed(): boolean {
|
||||||
return this._trimmed;
|
return this._trimmed;
|
||||||
|
@ -55,6 +55,7 @@ class UI {
|
|||||||
enable_comments: post.commentsEnabled,
|
enable_comments: post.commentsEnabled,
|
||||||
disqus_identifier: post.identifier,
|
disqus_identifier: post.identifier,
|
||||||
trimmed: post.trimmed,
|
trimmed: post.trimmed,
|
||||||
|
tags: post.tags
|
||||||
},
|
},
|
||||||
author: {
|
author: {
|
||||||
name: author.name,
|
name: author.name,
|
||||||
|
Loading…
Reference in New Issue
Block a user