Skip to content

Commit

Permalink
perf: replace luxon with dayjs (#608)
Browse files Browse the repository at this point in the history
* perf: replace luxon with dayjs

resolves #573

* fix(time): use time tag

* refactor(footer): copy right year time tag

Co-authored-by: Damien Robinson <damien.robinson@xcommedia.com.au>
  • Loading branch information
shadow81627 and damienrobinson committed Sep 18, 2020
1 parent 0ff4c40 commit 4383be1
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 45 deletions.
57 changes: 30 additions & 27 deletions components/layout/last-modified.vue
Original file line number Diff line number Diff line change
@@ -1,56 +1,59 @@
<template>
<client-only>
<v-col v-if="lastModified" cols="auto">
<v-card flat tile color="transparent">
<v-card-text class="py-2">
<span>Last modified</span>
<v-tooltip top>
<span>{{ relativeDate }}</span>
<template v-slot:activator="{ on, attrs }">
<span v-bind="attrs" v-on="on">{{
utc
? new Date(lastModified).toUTCString()
: DateTime.fromISO(lastModified).toRFC2822()
}}</span>
</template>
</v-tooltip>
</v-card-text>
</v-card>
</v-col>
<v-card v-if="lastModified" flat tile color="transparent">
<v-card-text class="py-2">
<span>Last modified</span>
<v-tooltip top>
<span>{{ relativeDate }}</span>
<template v-slot:activator="{ on, attrs }">
<time
v-bind="attrs"
itemprop="dateModified"
:content="lastModified.toISOString()"
:datetime="lastModified.toISOString()"
v-on="on"
>{{ lastModified.format(format) }}</time
>
</template>
</v-tooltip>
</v-card-text>
</v-card>
</client-only>
</template>

<script>
import { DateTime } from 'luxon';
import * as dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
dayjs.extend(relativeTime);
export default {
props: {
utc: Boolean,
interval: { type: Number, default: 60000 },
format: { type: String, default: 'ddd, DD MMM YYYY HH:mm:ss Z' },
},
data() {
return {
DateTime,
relativeDate: DateTime.fromISO(this.lastModified).toRelative(),
relativeDate: null,
timer: null,
};
},
computed: {
lastModified() {
const lastModified = process.client ? document.lastModified : null;
return new Date(
lastModified || this.$config.DATE_GENERATED,
).toISOString();
return dayjs(this.$config.DATE_GENERATED);
},
},
created() {
this.timer = setInterval(this.toRelativeDate, 1000);
this.toRelativeDate();
this.timer = setInterval(this.toRelativeDate, this.interval);
},
beforeDestroy() {
clearInterval(this.timer);
},
methods: {
toRelativeDate() {
const lastModified = DateTime.fromISO(this.lastModified);
this.relativeDate = lastModified.toRelative();
this.relativeDate = this.lastModified.fromNow();
},
},
};
Expand Down
6 changes: 4 additions & 2 deletions components/layout/the-footer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@
fixed-width
/>
<span>New Farm, Australia</span>
<span>© 2019 | Damien Robinson</span>
<span<time datetime="2019">2019</time> | Damien Robinson</span>
</v-card-text>
</v-card>
</v-col>
<v-spacer />
<last-modified v-bind="{ utc }" />
<v-col cols="auto">
<last-modified v-bind="{ utc }" />
</v-col>
</v-row>
</v-container>
</v-footer>
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
"@nuxtjs/pwa": "3.0.2",
"@nuxtjs/sitemap": "2.4.0",
"cross-env": "7.0.2",
"dayjs": "1.8.36",
"github-markdown-css": "4.0.0",
"koa": "2.13.0",
"luxon": "1.25.0",
"mailgo": "0.9.18",
"nuxt": "2.14.5",
"nuxt-fontawesome": "0.4.0",
Expand Down
20 changes: 10 additions & 10 deletions pages/portfolio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@
{{ description }}
</v-card-text>
<v-card-text v-if="startDate || endDate">
<span v-if="startDate"
>{{
DateTime.fromISO(startDate).toLocaleString(DateTime.DATE_MED)
}}
</span>
<time v-if="startDate" :datetime="new Date(startDate).toISOString()"
>{{ formatDate(startDate) }}
</time>
<span v-if="startDate && endDate">to</span>
<span v-if="endDate">{{
DateTime.fromISO(endDate).toLocaleString(DateTime.DATE_MED)
}}</span>
<time v-if="endDate" :datetime="new Date(endDate).toISOString()">{{
formatDate(endDate)
}}</time>
</v-card-text>
<v-card-actions class="mt-auto">
<v-spacer></v-spacer>
Expand Down Expand Up @@ -80,10 +78,9 @@

<script>
import { mdiWeb, mdiGithub, mdiOpenInNew } from '@mdi/js';
import { DateTime } from 'luxon';
import * as dayjs from 'dayjs';
export default {
data: () => ({
DateTime,
heading: 'Portfolio',
description: 'Explore demos and code for my projects.',
projects: [
Expand Down Expand Up @@ -143,6 +140,9 @@ export default {
],
}),
methods: {
formatDate(date) {
return dayjs(date).format('MMM D, YYYY');
},
backgroundColor: require.context(
'~/assets/img/portfolio?lqip-colors',
false,
Expand Down

1 comment on commit 4383be1

@vercel
Copy link

@vercel vercel bot commented on 4383be1 Sep 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.