This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user