From 506347ce9cc1b1ebed1400cbd118fb6cf28b1513 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 10 Aug 2023 15:32:34 +0100 Subject: [PATCH] feat: add pre-formatted date "dddd, d MMMM yyyy HH:mm" --- OliverBooth/Controllers/BlogApiController.cs | 1 + OliverBooth/Pages/Blog/Article.cshtml | 4 ++-- OliverBooth/Pages/Blog/Index.cshtml | 2 +- src/ts/BlogPost.ts | 6 ++++++ src/ts/app.ts | 1 + 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/OliverBooth/Controllers/BlogApiController.cs b/OliverBooth/Controllers/BlogApiController.cs index b134f86..4076bd3 100644 --- a/OliverBooth/Controllers/BlogApiController.cs +++ b/OliverBooth/Controllers/BlogApiController.cs @@ -43,6 +43,7 @@ public sealed class BlogApiController : ControllerBase author = post.AuthorId, title = post.Title, published = post.Published.ToUnixTimeSeconds(), + formattedDate = post.Published.ToString("dddd, d MMMM yyyy HH:mm"), updated = post.Updated?.ToUnixTimeSeconds(), humanizedTimestamp = post.Updated?.Humanize() ?? post.Published.Humanize(), excerpt = _blogService.GetExcerpt(post, out bool trimmed), diff --git a/OliverBooth/Pages/Blog/Article.cshtml b/OliverBooth/Pages/Blog/Article.cshtml index a75a161..e853552 100644 --- a/OliverBooth/Pages/Blog/Article.cshtml +++ b/OliverBooth/Pages/Blog/Article.cshtml @@ -29,14 +29,14 @@ @author.Name @author.Name • - + Published @published.Humanize() @if (post.Updated is { } updated) { - + Updated @updated.Humanize() } diff --git a/OliverBooth/Pages/Blog/Index.cshtml b/OliverBooth/Pages/Blog/Index.cshtml index dad690b..62dc808 100644 --- a/OliverBooth/Pages/Blog/Index.cshtml +++ b/OliverBooth/Pages/Blog/Index.cshtml @@ -19,7 +19,7 @@ {{author.name}} {{author.name}} - {{ post.date_humanized }} + {{ post.date_humanized }} {{#if post.enable_comments}} diff --git a/src/ts/BlogPost.ts b/src/ts/BlogPost.ts index fe7f0e6..0e0a984 100644 --- a/src/ts/BlogPost.ts +++ b/src/ts/BlogPost.ts @@ -10,6 +10,7 @@ private readonly _trimmed: boolean; private readonly _identifier: string; private readonly _humanizedTimestamp: string; + private readonly _formattedDate: string; constructor(json: any) { this._id = json.id; @@ -23,6 +24,7 @@ this._trimmed = json.trimmed; this._identifier = json.identifier; this._humanizedTimestamp = json.humanizedTimestamp; + this._formattedDate = json.formattedDate; } get id(): number { @@ -68,6 +70,10 @@ get humanizedTimestamp(): string { return this._humanizedTimestamp; } + + get formattedDate(): string { + return this._formattedDate; + } } export default BlogPost; \ No newline at end of file diff --git a/src/ts/app.ts b/src/ts/app.ts index 07720c8..afd8fe9 100644 --- a/src/ts/app.ts +++ b/src/ts/app.ts @@ -27,6 +27,7 @@ declare const Handlebars: any; excerpt: post.excerpt, url: post.url, date: TimeUtility.formatRelativeTimestamp(post.published), + formattedDate: post.formattedDate, date_humanized: `${post.updated ? "Updated" : "Published"} ${post.humanizedTimestamp}`, enable_comments: post.commentsEnabled, disqus_identifier: post.identifier,