Added meta to layouts

This commit is contained in:
2026-09-23 13:26:37 +02:00
parent 9ecea06209
commit fc38a1aafe
8 changed files with 106 additions and 27 deletions

View File

@@ -1,5 +1,16 @@
const DISPLAY = new Intl.DateTimeFormat('en-GB', {
timeZone: 'UTC',
day: 'numeric',
month: 'long',
year: 'numeric',
})
export function parseDate(value: string | null): Date | null {
if (!value) return null
const date = new Date(/(z|[+-]\d\d:\d\d)$/i.test(value) ? value : `${value}Z`)
return Number.isNaN(date.getTime()) ? null : date
}
export const formatDate = (date: Date): string => DISPLAY.format(date)
export const isoDate = (date: Date): string => date.toISOString().slice(0, 10)

18
src/lib/site/meta.ts Normal file
View File

@@ -0,0 +1,18 @@
import type { Article, Page, Routed } from './types'
export type Meta = {
title: string
description?: string
image?: string
noindex: boolean
}
const cover = (node: Routed) =>
node.collection === 'articles' ? (node as Article).summary.cover.image : null
export const metaOf = (node: Article | Page): Meta => ({
title: node.title,
description: node.summary.excerpt || undefined,
image: cover(node) ?? undefined,
noindex: node.noindex,
})