29 lines
734 B
TypeScript
29 lines
734 B
TypeScript
import type { CollectionEntry } from 'astro:content';
|
|
|
|
type DatedEntry =
|
|
| CollectionEntry<'stories'>
|
|
| CollectionEntry<'briefings'>
|
|
| CollectionEntry<'episodes'>;
|
|
|
|
export function newestFirst<T extends DatedEntry>(entries: T[]): T[] {
|
|
return [...entries].sort(
|
|
(a, b) => b.data.published.valueOf() - a.data.published.valueOf(),
|
|
);
|
|
}
|
|
|
|
export function guidesByReview(
|
|
entries: CollectionEntry<'guides'>[],
|
|
): CollectionEntry<'guides'>[] {
|
|
return [...entries].sort(
|
|
(a, b) => b.data.reviewed.valueOf() - a.data.reviewed.valueOf(),
|
|
);
|
|
}
|
|
|
|
export function formatDate(date: Date): string {
|
|
return new Intl.DateTimeFormat('en-GB', {
|
|
day: 'numeric',
|
|
month: 'short',
|
|
year: 'numeric',
|
|
}).format(date);
|
|
}
|