--- import FormattedDate from '../components/FormattedDate.astro'; import allLinks from '../data/links.ts'; type Link = (typeof allLinks)[number]; export interface Props { headingLevel?: 1 | 2 | 3 | 4 | 5 | 6, hideAuthor?: boolean, maxEntries?: number, }; const { headingLevel = 2, hideAuthor = false, maxEntries } = Astro.props; const headingElem = `h${headingLevel}`; const subHeadingElem = `h${headingLevel + 1}` const links: Link[] = maxEntries === undefined ? allLinks : allLinks.sort(sortByDateAddedDescending).slice(0, maxEntries); const distinctYears: string[] = links .map(link => link.isoDateAdded.slice(0,4)) .reduce((acc, curr) => acc.includes(curr) ? acc : [...acc, curr], []) .sort((a, b) => Number.parseInt(b) - Number.parseInt(a)); function matchesYear(year: string) { return (link: (typeof links)[number]) => link.isoDateAdded.slice(0,4) === year; } function sortByDateAddedDescending(link1: (typeof links)[number], link2: (typeof links)[number]) { const date1 = new Date(link1.isoDateAdded).getTime(); const date2 = new Date(link2.isoDateAdded).getTime(); return date2 - date1; } const canonicalLinksUrl = new URL('links', Astro.site) ---
My links `} /> { distinctYears.map(year => ( ${year} `} />
    { links.filter(matchesYear(year)).sort(sortByDateAddedDescending).map(link => (
  • )) }
)) } { (maxEntries !== undefined && maxEntries < allLinks.length) ? : <> }