Skip to content

Commit

Permalink
Added updatedAt attribute in blog meta
Browse files Browse the repository at this point in the history
  • Loading branch information
grgprarup committed Jul 5, 2024
1 parent f1ae77b commit dd2b819
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 11 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ A beautiful blogging platform for the JankariTech peoples.
authorName: John Doe
authorAvatar: https://some.link.jpg (must be an image URL, **required**)
authorLink: https://github.com/John
createdAt: Oct 30, 2019 (must be in the format `MM dd, yyyy`, **required**)
createdAt: Oct 30, 2019 (can be in the format `MMM dd, yyyy` or `MMMM dd, yyyy`, **required**)
updatedAt: October 30, 2023 (can be in the format `MMM dd, yyyy` or `MMMM dd, yyyy`, **optional**)
tags: vue, jest, unit, testing (separate multiple items with a comma `,` character, **required**)
banner: https://some.link.jpg (must be an image URL, **required**)
seriesTitle: Unit Testing is Fun (if only this post belongs to a series, **optional**)
Expand Down
24 changes: 21 additions & 3 deletions lint/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const requiredMeta = [
]

const optionalMeta = [
"updatedAt",
"seriesTitle",
"episode"
]
Expand Down Expand Up @@ -91,11 +92,28 @@ function lintMeta (key) {
})

// check if the createdAt is set with proper format
let createdAt
if (peekData.createdAt) {
const regex = /[A-Za-z]+\s\d{1,2},\s\d{4}/g
createdAt = new Date(peekData.createdAt)
if (isNaN(createdAt.getTime())) {
log.error(`Invalid createdAt date format in ${key}`)
success = false
}
}

if (!regex.test(peekData.createdAt)) {
log.error(`Invalid date format in ${key}`)
if (peekData.updatedAt) {
const updatedAt = new Date(peekData.updatedAt)
// check if the updatedAt is set with proper format
if (isNaN(updatedAt.getTime())) {
log.error(`Invalid updatedAt date format in ${key}`)
success = false
}
// check if the updatedAt is later than createdAt
if (createdAt.getTime() === updatedAt.getTime()) {
log.error(`Updated date is same as created date in ${key}`)
success = false
} else if (createdAt.getTime() > updatedAt.getTime()) {
log.error(`Updated date is earlier than created date in ${key}`)
success = false
}
}
Expand Down
12 changes: 11 additions & 1 deletion src/components/BlogPeek.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@
</a>
<div v-else class="author-name">{{ authorName }}</div>
<div class="created-at" title="Created Timestamp">
{{ moment(createdAt).format("MMM DD, YYYY") }}
Published:
{{ moment(createdAt).format("MMMM DD, YYYY") }}
({{ moment(createdAt).fromNow() }})
</div>
<div v-if="updatedAt" class="updated-at" title="Updated Timestamp">
Updated:
{{ moment(updatedAt).format("MMMM DD, YYYY") }}
({{ moment(updatedAt).fromNow() }})
</div>
</div>
</div>
<div class="blog-peek--content">
Expand Down Expand Up @@ -101,6 +107,10 @@ defineProps({
type: [Date, String],
required: true
},
updatedAt: {
type: [Date, String],
required: true
},
contentLength: {
type: Number,
default: 0
Expand Down
15 changes: 10 additions & 5 deletions src/components/detail/HeadSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@
>
{{ peek.authorName }}
</a>
<div class="vl">|</div>
<div class="created-at">
<mdi-clock />
<span>{{ $moment(peek.createdAt).format("LLLL") }}</span>
Published:
<span>{{ $moment(peek.createdAt).format("MMMM DD, YYYY") }}</span>
</div>
<div v-if="peek.updatedAt" class="vl">|</div>
<div v-if="peek.updatedAt" class="updated-at">
Updated:
<span>{{ $moment(peek.updatedAt).format("MMMM DD, YYYY") }}</span>
</div>
</div>
</div>
Expand Down Expand Up @@ -96,17 +102,16 @@ const fallbackBanner = computed(() => {
padding-inline: 0.5rem;
}
.created-at {
.created-at, .updated-at, .vl {
display: flex;
align-items: center;
color: grey;
font-size: 0.875rem;
line-height: 1.2rem;
padding-inline: 0.5rem;
padding-inline: 0.2rem;
span {
margin-left: 0.2rem;
margin-top: 0.1rem;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/styles/blogPeek.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
font-weight: 500;
}

.created-at {
.created-at, .updated-at {
font-size: 0.75rem;
}

Expand Down
1 change: 1 addition & 0 deletions src/views/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
:key="index"
:title="item.title"
:created-at="item.createdAt"
:updated-at="item.updatedAt"
:author-name="item.authorName"
:author-link="item.authorLink"
:author-avatar="item.authorAvatar"
Expand Down

0 comments on commit dd2b819

Please sign in to comment.