Something went wrong. Try again.
doll.systems community website
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435import type { CountedLink, PageMetadata } from './layouts';const dateFormat = new Intl.DateTimeFormat('en-GB', { day: '2-digit', month: 'short', year: 'numeric', timeZone: 'UTC',});export type MetaValue = { text: string; tag: 'a' | 'time' | 'span'; attributes: Record<string, string>;};export type MetaItem = { values: MetaValue[]; category?: boolean };const item = ( text: string, tag: MetaValue['tag'] = 'span', attributes: Record<string, string> = {},): MetaValue => ({ text, tag, attributes });const countedLinks = (links: CountedLink[], attributes: Record<string, string> = {}) => links.map(({ name, href, count }) => item(`${name} (${count})`, 'a', { href, ...attributes }));export const metadataItems = ( { authors = [], date, categories = [] }: PageMetadata, minutes?: number,): MetaItem[] => [ { values: countedLinks(authors, { rel: 'author' }) }, { values: date ? [item(dateFormat.format(new Date(date)), 'time', { datetime: date.slice(0, 10) })] : [], }, { values: minutes ? [item(`${minutes} min read`)] : [] }, { values: countedLinks(categories), category: true }, ].filter(({ values }) => values.length);