From 4db9fc3b26286b3b691f0c844607be82a007c0bf Mon Sep 17 00:00:00 2001 From: Renoir Boulanger Date: Sun, 20 Oct 2024 16:38:53 -0400 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=A4=96=20createdAt,updatedAt=20b?= =?UTF-8?q?ecause=20it=20was=20a=20bad=20idea=20to=20change=20that.=20Mana?= =?UTF-8?q?gement=20side?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/blog/BlogListModelByYear.vue | 2 +- components/global/AppContentDate.vue | 10 +++--- lib/model/content/break-into-years.ts | 14 ++++---- lib/model/content/model.ts | 21 +++++------- lib/model/date.ts | 4 +-- lib/runtime/nuxt-feed.ts | 44 ++++++++++++------------- pages/blog/_year/_month/_slug.vue | 8 ++--- pages/blog/_year/_month/index.vue | 23 ++++--------- pages/blog/_year/index.vue | 19 ++--------- pages/blog/reviewing.vue | 6 ++-- pages/glossary/index.vue | 2 +- pages/index.vue | 4 +-- pages/projects/index.vue | 5 ++- pages/projets/index.vue | 2 +- 14 files changed, 69 insertions(+), 95 deletions(-) diff --git a/components/blog/BlogListModelByYear.vue b/components/blog/BlogListModelByYear.vue index 99cb185b15..01cc17821b 100644 --- a/components/blog/BlogListModelByYear.vue +++ b/components/blog/BlogListModelByYear.vue @@ -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" diff --git a/components/global/AppContentDate.vue b/components/global/AppContentDate.vue index 0620142170..66a61a9ec8 100644 --- a/components/global/AppContentDate.vue +++ b/components/global/AppContentDate.vue @@ -1,5 +1,5 @@ @@ -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] @@ -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({ @@ -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, diff --git a/lib/model/content/break-into-years.ts b/lib/model/content/break-into-years.ts index e6e3186838..6a74701737 100644 --- a/lib/model/content/break-into-years.ts +++ b/lib/model/content/break-into-years.ts @@ -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 @@ -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. } diff --git a/lib/model/content/model.ts b/lib/model/content/model.ts index 09d0e5a080..a49ca5be87 100644 --- a/lib/model/content/model.ts +++ b/lib/model/content/model.ts @@ -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 @@ -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 } @@ -138,6 +131,8 @@ export const isNuxtContentResult = ( export const queryNuxtContent = async ( $content: Context['$content'], route: Context['route'], + year?: string, + month?: string, ): Promise => { let contents: INuxtContentResult[] = [] const { query = {} as Context['route']['query'] } = route @@ -157,7 +152,7 @@ export const queryNuxtContent = async ( let ds = $content('blog', { deep: true }) .sortBy('created', 'desc') .only([ - 'created', + 'createdAt', 'excerpt', 'locale', 'path', @@ -166,7 +161,7 @@ export const queryNuxtContent = async ( 'slug', 'tags', 'title', - 'updated', + 'updatedAt', ]) if (q) { ds = ds.search(q) diff --git a/lib/model/date.ts b/lib/model/date.ts index 52aa93e26c..ce8c5c7126 100644 --- a/lib/model/date.ts +++ b/lib/model/date.ts @@ -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 => { @@ -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] diff --git a/lib/runtime/nuxt-feed.ts b/lib/runtime/nuxt-feed.ts index 7633eabfbb..169dd51d53 100644 --- a/lib/runtime/nuxt-feed.ts +++ b/lib/runtime/nuxt-feed.ts @@ -11,13 +11,11 @@ const EXAMPLE_NUXT_CONTENT_RESULT: Partial[] = [ 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', }, ] @@ -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 { @@ -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', @@ -115,7 +115,7 @@ export const createNuxtFeedCreate = 'slug', 'tags', 'title', - 'updated', + 'updatedAt', ]) const p1 = (await ds1.fetch()) as INuxtContentResult[] all.push( @@ -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', @@ -138,7 +138,7 @@ export const createNuxtFeedCreate = 'slug', 'tags', 'title', - 'updated', + 'updatedAt', ]) const p2 = (await ds2.fetch()) as INuxtContentResult[] all.push(...p2) @@ -146,9 +146,9 @@ export const createNuxtFeedCreate = // ------ BEGIN [ /glossary ] ------------------------------ const ds3 = $content('glossary', { deep: true }) - .sortBy('created', 'desc') + .sortBy('createdAt', 'desc') .only([ - 'created', + 'createdAt', 'description', 'excerpt', 'locale', @@ -157,7 +157,7 @@ export const createNuxtFeedCreate = 'slug', 'tags', 'title', - 'updated', + 'updatedAt', ]) const p3 = (await ds3.fetch()) as INuxtContentResult[] all.push(...p3) @@ -184,17 +184,17 @@ 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) @@ -202,7 +202,7 @@ export const createNuxtFeedCreate = failedDates.push({ path: article.path, propertyName: 'article.updated', - value: article.updated, + value: article.updatedAt, }) } diff --git a/pages/blog/_year/_month/_slug.vue b/pages/blog/_year/_month/_slug.vue index d66ab73838..e1595a557d 100644 --- a/pages/blog/_year/_month/_slug.vue +++ b/pages/blog/_year/_month/_slug.vue @@ -1,11 +1,11 @@