fix: use correct formatted date on blog card attr

This commit is contained in:
Oliver Booth 2023-10-12 16:58:10 +01:00
parent 0fabcf59c3
commit 3186ce9b50
Signed by: oliverbooth
GPG Key ID: E60B570D1B7557B5
3 changed files with 13 additions and 6 deletions

View File

@ -82,8 +82,9 @@ public sealed class BlogApiController : ControllerBase
author = post.Author.Id, author = post.Author.Id,
title = post.Title, title = post.Title,
published = post.Published.ToUnixTimeSeconds(), published = post.Published.ToUnixTimeSeconds(),
formattedDate = post.Published.ToString("dddd, d MMMM yyyy HH:mm"),
updated = post.Updated?.ToUnixTimeSeconds(), updated = post.Updated?.ToUnixTimeSeconds(),
formattedPublishDate = post.Published.ToString("dddd, d MMMM yyyy HH:mm"),
formattedUpdateDate = post.Updated?.ToString("dddd, d MMMM yyyy HH:mm"),
humanizedTimestamp = post.Updated?.Humanize() ?? post.Published.Humanize(), humanizedTimestamp = post.Updated?.Humanize() ?? post.Published.Humanize(),
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,

View File

@ -13,7 +13,8 @@ class BlogPost {
private readonly _trimmed: boolean; private readonly _trimmed: boolean;
private readonly _identifier: string; private readonly _identifier: string;
private readonly _humanizedTimestamp: string; private readonly _humanizedTimestamp: string;
private readonly _formattedDate: string; private readonly _formattedPublishDate: string;
private readonly _formattedUpdateDate: string;
private readonly _tags: string[]; private readonly _tags: string[];
constructor(json: any) { constructor(json: any) {
@ -29,7 +30,8 @@ class BlogPost {
this._trimmed = json.trimmed; this._trimmed = json.trimmed;
this._identifier = json.identifier; this._identifier = json.identifier;
this._humanizedTimestamp = json.humanizedTimestamp; this._humanizedTimestamp = json.humanizedTimestamp;
this._formattedDate = json.formattedDate; this._formattedPublishDate = json.formattedPublishDate;
this._formattedUpdateDate = json.formattedUpdateDate;
this._tags = json.tags; this._tags = json.tags;
} }
@ -85,8 +87,12 @@ class BlogPost {
return this._humanizedTimestamp; return this._humanizedTimestamp;
} }
get formattedDate(): string { get formattedPublishDate(): string {
return this._formattedDate; return this._formattedPublishDate;
}
get formattedUpdateDate(): string {
return this._formattedUpdateDate;
} }
} }

View File

@ -50,7 +50,7 @@ class UI {
excerpt: post.excerpt, excerpt: post.excerpt,
url: `/blog/${post.url.year}/${post.url.month}/${post.url.day}/${post.url.slug}`, url: `/blog/${post.url.year}/${post.url.month}/${post.url.day}/${post.url.slug}`,
date: TimeUtility.formatRelativeTimestamp(post.published), date: TimeUtility.formatRelativeTimestamp(post.published),
formattedDate: post.formattedDate, formattedDate: post.updated ? post.formattedUpdateDate : post.formattedPublishDate,
date_humanized: `${post.updated ? "Updated" : "Published"} ${post.humanizedTimestamp}`, date_humanized: `${post.updated ? "Updated" : "Published"} ${post.humanizedTimestamp}`,
enable_comments: post.commentsEnabled, enable_comments: post.commentsEnabled,
disqus_identifier: post.identifier, disqus_identifier: post.identifier,