Added meta to layouts
This commit is contained in:
@@ -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
18
src/lib/site/meta.ts
Normal 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,
|
||||
})
|
||||
Reference in New Issue
Block a user