Skip to content

Commit

Permalink
MODIFIED: better news post date handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sd-ditoy committed Aug 7, 2024
1 parent 60db79a commit bc06f88
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/components/atoms/PostItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
</router-link>
</div>
<div class="content" :class="`postType-${type}`">
<div class="time" v-if="type === 'news'">
<div class="time" v-if="type === 'news'" :title="date">
<SVGClock />
{{ getRelativeDate }}
<time :datetime="date">{{ getRelativeDate }}</time>
</div>
<h3 v-if="type === 'news'">{{postItemData.content[0].title}}</h3>
<h3 v-else>{{postItemData.title}}</h3>
Expand Down Expand Up @@ -89,7 +89,16 @@ export default {
//---------------------------------------------------
computed: {
getRelativeDate() {
return dayjs().to(this.postItemData.publish_date);
const time = (new Date()).toISOString().split('T')[1];
const publishDate = this.postItemData?.publish_date;
if (publishDate) {
const relative = dayjs().to(`${publishDate}T${time}`);
return relative === 'a few seconds ago' ? 'Today' : relative;
}
return 'Today';
},
date() {
return this.postItemData?.publish_date || '';
},
postImage() {
if (this.type === 'news') {
Expand Down

0 comments on commit bc06f88

Please sign in to comment.