Skip to content

Commit

Permalink
chore: 🤖 createdAt,updatedAt because it was a bad idea to change that…
Browse files Browse the repository at this point in the history
…. Management side
  • Loading branch information
renoirb committed Oct 28, 2024
1 parent d0d83f0 commit b477661
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 95 deletions.
2 changes: 1 addition & 1 deletion components/blog/BlogListModelByYear.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
path: content.path,
meta: {
locale: content.locale ? content.locale : 'en-CA',
date: content.date,
date: content.createdAt,
},
}"
class="font-serif text-xl italic no-underline"
Expand Down
10 changes: 5 additions & 5 deletions components/global/AppContentDate.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<time v-if="content.date" :datetime="datetime" :title="textual">
<time v-if="content.createdAt" :datetime="datetime" :title="textual">
{{ yyyymmdd }}
</time>
</template>
Expand Down Expand Up @@ -35,7 +35,7 @@
},
computed: {
yyyymmdd(): string {
const { date } = this.content
const date = this.content?.createdAt
let out = ''
if (date) {
const first = date.split('T')[0]
Expand All @@ -44,8 +44,8 @@
return out
},
datetime(): string {
const { date } = this.content
return date
const createdAt = this.content?.createdAt
return createdAt
},
textual(): string {
return this.formatDate({
Expand All @@ -60,7 +60,7 @@
let out = ''
try {
const locale = this.content?.locale ?? 'fr-CA'
out = this.content?.date ?? ''
out = this.content?.createdAt ?? ''
const { temporalDate = '' } = getPrettyfiedTemporalDate(
this.content,
locale,
Expand Down
14 changes: 7 additions & 7 deletions lib/model/content/break-into-years.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ export const extractYearFromDateString = (dateString: string | ''): number => {
}

export const extractYearFromRecord = (
content: Record<'created' | 'updated', string>,
content: Record<'createdAt' | 'updatedAt', string>,
): number => {
let out: number = 0

const { created = '', updated } = content
const { createdAt = '', updatedAt } = content

if (created !== '') {
out = extractYearFromDateString(created)
if (createdAt !== '') {
out = extractYearFromDateString(createdAt)
}
if (out === 0 && updated) {
out = extractYearFromDateString(updated)
if (out === 0 && updatedAt) {
out = extractYearFromDateString(updatedAt)
}

return out
Expand Down Expand Up @@ -58,5 +58,5 @@ export const breakIntoYears = (
// Make sure it's sorted by year, chronologically
return out.filter(([y]) => y !== 0).sort((a, b) => b[0] - a[0])
// ^^^^^^^
// | We set all with no created date into a bucket aside and don't display them.
// | We set all with no createdAt date into a bucket aside and don't display them.
}
21 changes: 8 additions & 13 deletions lib/model/content/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,16 @@ export interface IBaseNuxtContentResult extends IResult {
/**
* Nuxt internal file creation date
*
* #ToLearn: Figure Out Unsure if it's filesystem
* Hard-coded, per file, desired publication date.
* If it's in the file (i.e. hardcoded), otherwise Nuxt will take from the filesystem.
*/
createdAt: string
/**
* Nuxt internal file updated date
*
* #ToLearn: Figure Out Unsure if it's filesystem
* If it's in the file (i.e. hardcoded), otherwise Nuxt will take from the filesystem.
*/
updatedAt: string
/**
* Hard-coded, per file, desired publication date.
*/
created: string
/**
* Hard-coded, per file, desired last updated date.
*/
updated: string
dir: string
extension: string
path: string
Expand Down Expand Up @@ -102,7 +95,7 @@ export type INuxtContentPrevNext = Pick<
export interface INuxtContentIndexResult
extends Pick<
INuxtContentResult,
'created' | 'updated' | 'locale' | 'path' | 'slug' | 'title'
'createdAt' | 'updatedAt' | 'locale' | 'path' | 'slug' | 'title'
> {
prettyfiedTemporalDate?: IPrettyfiedTemporalDate
}
Expand Down Expand Up @@ -138,6 +131,8 @@ export const isNuxtContentResult = (
export const queryNuxtContent = async (
$content: Context['$content'],
route: Context['route'],
year?: string,
month?: string,
): Promise<INuxtContentResult[]> => {
let contents: INuxtContentResult[] = []
const { query = {} as Context['route']['query'] } = route
Expand All @@ -157,7 +152,7 @@ export const queryNuxtContent = async (
let ds = $content('blog', { deep: true })
.sortBy('created', 'desc')
.only([
'created',
'createdAt',
'excerpt',
'locale',
'path',
Expand All @@ -166,7 +161,7 @@ export const queryNuxtContent = async (
'slug',
'tags',
'title',
'updated',
'updatedAt',
])
if (q) {
ds = ds.search(q)
Expand Down
4 changes: 2 additions & 2 deletions lib/model/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const formatTemporal = (
}

export const getPrettyfiedTemporalDate = (
content: Record<'created' | 'updated', string>,
content: Record<'createdAt' | 'updatedAt', string>,
locale = 'fr-CA',
format?: Intl.DateTimeFormatOptions,
): IPrettyfiedTemporalDate => {
Expand All @@ -83,7 +83,7 @@ export const getPrettyfiedTemporalDate = (
*
* @TODO #23 It MUST be a string that has no Z in its notation.
*/
let field = content?.date ?? content?.created ?? content?.updated ?? 0
let field = content?.date ?? content?.createdAt ?? content?.updatedAt ?? 0

if (/\d\d\d\d-\d\d-\d\dT/.test(field)) {
field = field.split('T')[0]
Expand Down
44 changes: 22 additions & 22 deletions lib/runtime/nuxt-feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ const EXAMPLE_NUXT_CONTENT_RESULT: Partial<INuxtContentResult>[] = [
title:
'Things I’ve worked on in the last two years while maintaining WebPlatform.org',
locale: 'en-CA',
created: '2017-02-09T00:00:00.000Z',
updated: '2023-11-20T00:00:00.000Z',
createdAt: '2017-02-09T00:00:00.000Z',
updatedAt: '2023-11-20T00:00:00.000Z',
dir: '/blog/2017/02',
path: '/blog/2017/02/things-i-ve-worked-on-while-maintaining-webplatform-org',
slug: 'things-i-ve-worked-on-while-maintaining-webplatform-org',
createdAt: '2024-10-01T17:48:55.423Z',
updatedAt: '2024-10-01T17:48:55.424Z',
},
]

Expand All @@ -36,14 +34,16 @@ const baseUrlNoTrailingSlash = (u: string): string => {

let failedDatesOnce = false

const dateStringToDateObject = (created, tz) => {
const dateStringToDateObject = (createdAt, tz) => {
// #TODO Make sure we return with proper time offset for Montreal, not UTC
const createdNormalized =
!!created && !created.includes('T') ? created + 'T00:00:00.000Z' : created
const createdAtNormalized =
!!createdAt && !createdAt.includes('T')
? createdAt + 'T00:00:00.000Z'
: createdAt
let published: Date | undefined
let instant
try {
instant = Temporal.Instant.from(createdNormalized)
instant = Temporal.Instant.from(createdAtNormalized)
instant = instant.toZonedDateTimeISO(tz)
published = new Date(instant.epochMilliseconds)
} catch {
Expand Down Expand Up @@ -102,10 +102,10 @@ export const createNuxtFeedCreate =

// ------ BEGIN [ /blog ] ------------------------------
const ds1 = $content('blog', { deep: true })
.sortBy('created', 'desc')
.sortBy('createdAt', 'desc')
.only([
'categories',
'created',
'createdAt',
'description',
'dir',
'excerpt',
Expand All @@ -115,7 +115,7 @@ export const createNuxtFeedCreate =
'slug',
'tags',
'title',
'updated',
'updatedAt',
])
const p1 = (await ds1.fetch()) as INuxtContentResult[]
all.push(
Expand All @@ -127,9 +127,9 @@ export const createNuxtFeedCreate =

// ------ BEGIN [ /code-review ] ------------------------------
const ds2 = $content('code-review', { deep: true })
.sortBy('created', 'desc')
.sortBy('createdAt', 'desc')
.only([
'created',
'createdAt',
'description',
'excerpt',
'locale',
Expand All @@ -138,17 +138,17 @@ export const createNuxtFeedCreate =
'slug',
'tags',
'title',
'updated',
'updatedAt',
])
const p2 = (await ds2.fetch()) as INuxtContentResult[]
all.push(...p2)
// ------ END [ /code-review ] ------------------------------

// ------ BEGIN [ /glossary ] ------------------------------
const ds3 = $content('glossary', { deep: true })
.sortBy('created', 'desc')
.sortBy('createdAt', 'desc')
.only([
'created',
'createdAt',
'description',
'excerpt',
'locale',
Expand All @@ -157,7 +157,7 @@ export const createNuxtFeedCreate =
'slug',
'tags',
'title',
'updated',
'updatedAt',
])
const p3 = (await ds3.fetch()) as INuxtContentResult[]
all.push(...p3)
Expand All @@ -184,25 +184,25 @@ export const createNuxtFeedCreate =
}
*/

const published = dateStringToDateObject(article.created, timeZone)
const published = dateStringToDateObject(article.createdAt, timeZone)
if (published) {
Reflect.set(item, 'published', published)
} else {
failedDates.push({
path: article.path,
propertyName: 'article.created',
value: article.created,
propertyName: 'article.createdAt',
value: article.createdAt,
})
}
const updated = dateStringToDateObject(article.updated, timeZone)
const updated = dateStringToDateObject(article.updatedAt, timeZone)
if (updated) {
// Because "date" field is for updated
Reflect.set(item, 'date', updated)
} else {
failedDates.push({
path: article.path,
propertyName: 'article.updated',
value: article.updated,
value: article.updatedAt,
})
}

Expand Down
8 changes: 4 additions & 4 deletions pages/blog/_year/_month/_slug.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<template>
<div class="pages__blog__year__month__slug--item">
<div :key="content.slug + '--' + content.created">
<div :key="content.slug + '--' + content.createdAt">
<keep-alive>
<app-very-old-article
:preamble="preamble"
:locale="content.locale || 'en-CA'"
:date="content.created"
:date="content.createdAt"
class="my-4"
alert-type="warn"
role="alert"
Expand Down Expand Up @@ -198,16 +198,16 @@
* Ideally, should:
* - Be `status: publish`
* - Not have a `redirect: #####`
* - At the neighbooring published date
* - At the neighbooring published (createdAt) date
*
* [1]: ~/blog/2015/11/recover-discourse-backup-change-domain-name
* [2]: ~/blog/2024/03/managing-email-aliases-with-protonmail-and-simplelogin-to-sort-automatically-into-inbox-folders-based-local-part
* [3]: ~/blog/2024/03/managing-email-aliases-with-protonmail-automatic-sorting
*/
})
.only(['title', 'path', 'locale'])
.sortBy('created', 'asc')
.surround(slug)
.sortBy('createdAt', 'asc')
const items = await dal.fetch()
const [prev, next] = items
Expand Down
23 changes: 7 additions & 16 deletions pages/blog/_year/_month/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,15 @@
components: {
'blog-list-model-by-year': BlogListModelByYear,
},
async asyncData({ $content, params }) {
const { year, month } = params
async asyncData({ $content, route, params }) {
let contents: INuxtContentIndexResult[] = []
try {
contents = await $content('blog', year, month, { deep: true })
.sortBy('created', 'desc')
.only([
'created',
'excerpt',
'locale',
'path',
'slug',
'tags',
'title',
'updated',
])
.fetch()
contents = await queryNuxtContent(
$content,
route,
params.year,
params.month,
)
} catch (_) {
// ...
}
Expand Down
19 changes: 2 additions & 17 deletions pages/blog/_year/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,10 @@
components: {
'blog-list-model-by-year': BlogListModelByYear,
},
async asyncData({ $content, params }) {
const { year } = params
async asyncData({ $content, route, params }) {
let contents: INuxtContentIndexResult[] = []
try {
contents = await $content('blog', year, { deep: true })
.sortBy('created', 'desc')
.only([
'created',
'excerpt',
'locale',
'path',
'preamble',
'slug',
'tags',
'title',
'updated',
])
.fetch()
contents = await queryNuxtContent($content, route, params.year)
} catch (_) {
// ..
}
Expand Down
Loading

0 comments on commit b477661

Please sign in to comment.