Skip to content

Commit 7981e79

Browse files
committed
Use NuxtTime for hydration issues
1 parent 1c249a4 commit 7981e79

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

components/section/BlogPosts.vue

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@ const props = defineProps({
1919
<div class="flex-1 text-lg font-bold md:text-xl">
2020
{{ article.title }}
2121
</div>
22-
<div v-if="show_dates" class="text-sm font-light text-gray-400">
23-
{{
24-
new Date(article.date).toLocaleDateString("en-US", {
25-
month: "long",
26-
day: "numeric",
27-
year: "numeric",
28-
})
29-
}}
30-
</div>
22+
<NuxtTime
23+
v-if="show_dates"
24+
:datetime="article.date"
25+
class="text-sm font-light text-gray-400"
26+
year="numeric"
27+
month="short"
28+
day="2-digit"
29+
/>
3130
</div>
32-
3331
<div class="line-clamp-3 text-sm text-gray-300">
3432
{{ article.description }}
3533
</div>

pages/articles/index.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,13 @@ function toggleCategory(cat) {
9191
<div class="col-span-4 lg:col-span-3">
9292
<div class="grid grid-cols-10 gap-y-4 lg:gap-y-6">
9393
<template v-for="article in visibleArticles" :key="article._id">
94-
<div class="col-span-10 lg:col-span-2">
95-
{{ formatDate(article.date) }}
96-
</div>
94+
<NuxtTime
95+
:datetime="article.date"
96+
class="col-span-10 lg:col-span-2"
97+
year="numeric"
98+
month="short"
99+
day="2-digit"
100+
/>
97101
<div class="col-span-10 lg:col-span-8">
98102
<div class="flex-col space-y-2">
99103
<NuxtLink class="text-orange-500" :to="article.path">{{

pages/talks.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,13 @@ const talks = [
7373
<h1 class="my-6 text-2xl font-extrabold">Talks</h1>
7474
<div class="grid grid-cols-10 gap-y-6">
7575
<template v-for="(talk, ix) in talks" :key="ix">
76-
<div class="col-span-2">{{ formatDate(talk.date) }}</div>
76+
<NuxtTime
77+
:datetime="talk.date"
78+
class="col-span-2"
79+
year="numeric"
80+
month="short"
81+
day="2-digit"
82+
/>
7783
<div class="col-span-8">
7884
<div class="flex-col space-y-2">
7985
<!-- <div class=""> -->

utils/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Warning! This utility was created before becoming aware of <NuxtTime>.
2+
//
3+
// Date formatting can cause hydration issues due to the difference locale on server and client.
4+
// See: https://www.leopold.is/blog/nuxt-hydration-issues-and-dates/
15
export const formatDate = function (date) {
26
return new Date(date).toLocaleDateString("en-US", {
37
month: "short",

0 commit comments

Comments
 (0)