Files
blog/frontend/shared/utils/format.ts
T
davide 31dbf56235 Show the author and publication time on articles
Strapi already records which admin user created an entry, so the byline needs
no extra field to fill in: the Article content type sets populateCreatorFields
and the API layer exposes only that user's firstname and lastname. The name
also feeds the BlogPosting structured data.

Also fixes the gap below the article header, which until now came from the
cover image's margin and therefore vanished on articles without a cover,
leaving the body text against the byline.
2026-08-25 15:30:57 +02:00

18 lines
780 B
TypeScript

/** Human-readable date for display; returns an empty string when unset. */
export function formatDate(value: string | null | undefined, locale = 'en-GB'): string {
if (!value) return ''
return new Intl.DateTimeFormat(locale, { dateStyle: 'long' }).format(new Date(value))
}
/** Date and time of publication, shown in the article byline. */
export function formatDateTime(value: string | null | undefined, locale = 'en-GB'): string {
if (!value) return ''
return new Intl.DateTimeFormat(locale, { dateStyle: 'long', timeStyle: 'short' })
.format(new Date(value))
}
/** Machine-readable date for the `datetime` attribute and structured data. */
export function isoDate(value: string | null | undefined): string {
return value ? new Date(value).toISOString() : ''
}