From f3cf53938e484f1a7a921872263572e2fa2fa63d Mon Sep 17 00:00:00 2001 From: Daniel Nitsikopoulos Date: Sat, 25 Feb 2023 15:04:36 +1100 Subject: [PATCH] Use local times for post dates --- app/decorators/bookmarks/decorator.rb | 4 ++++ app/templates/layouts/app.html.slim | 1 + app/templates/shared/_bookmark.html.slim | 5 +++-- app/templates/shared/_post.html.slim | 2 +- public/assets/index.js | 9 +++++++++ 5 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 public/assets/index.js diff --git a/app/decorators/bookmarks/decorator.rb b/app/decorators/bookmarks/decorator.rb index bd390bf..2938c07 100644 --- a/app/decorators/bookmarks/decorator.rb +++ b/app/decorators/bookmarks/decorator.rb @@ -10,6 +10,10 @@ module Adamantium published_at.strftime("%e %B, %Y") end + def machine_published_at + published_at.rfc2822 + end + def syndicated? !syndication_sources.empty? end diff --git a/app/templates/layouts/app.html.slim b/app/templates/layouts/app.html.slim index 0f725eb..556e4ae 100644 --- a/app/templates/layouts/app.html.slim +++ b/app/templates/layouts/app.html.slim @@ -22,6 +22,7 @@ html link rel="icon" type="image/x-icon" href="/assets/favicon.ico" script data-domain="dnitza.com" src="https://stats.dnitza.com/js/script.js" defer="true" + script src="/assets/index.js" script src="https://unpkg.com/htmx.org@1.8.4" integrity="sha384-wg5Y/JwF7VxGk4zLsJEcAojRtlVp1FKKdGy1qN+OMtdq72WRvX/EdRdqg/LOhYeV" crossorigin="anonymous" diff --git a/app/templates/shared/_bookmark.html.slim b/app/templates/shared/_bookmark.html.slim index 041da29..f13ade1 100644 --- a/app/templates/shared/_bookmark.html.slim +++ b/app/templates/shared/_bookmark.html.slim @@ -7,6 +7,7 @@ div class="mb-8" = bookmark.content == render :tags, tags: bookmark.tags - p class="text-sm u-url text-blue-400 hover:text-blue-600 dark:hover:text-blue-200" + p class="text-sm text-blue-400" a href="/bookmark/#{bookmark.slug}" - = bookmark.display_published_at + time class="dt-published" datetime=bookmark.machine_published_at + = bookmark.display_published_at diff --git a/app/templates/shared/_post.html.slim b/app/templates/shared/_post.html.slim index 4ab9747..42cf29f 100644 --- a/app/templates/shared/_post.html.slim +++ b/app/templates/shared/_post.html.slim @@ -7,5 +7,5 @@ div class="mb-8 h-entry" == render :tags, tags: post.tags p class="text-sm text-blue-400" - time class="dt-published" datetime=post.published_at + time class="dt-published" datetime=post.machine_published_at = post.display_published_at diff --git a/public/assets/index.js b/public/assets/index.js new file mode 100644 index 0000000..f76507c --- /dev/null +++ b/public/assets/index.js @@ -0,0 +1,9 @@ +(function() { + document.addEventListener("DOMContentLoaded", function () { + const times = document.querySelectorAll('time'); + times.forEach((time) => { + const oldDtime = Date.parse(time.dateTime); + time.innerHTML = new Date(oldDtime).toLocaleDateString(navigator.language, { weekday:"long", year:"numeric", month:"short", day:"numeric"}); + }); + }); +})();