---
import '@/styles/pages/news-list.css'

import { getCollection } from 'astro:content'

import PageLayout from '@layouts/PageLayout.astro'

const news = await getCollection('news')
---

<PageLayout title="Notizie | PHC">
    <h1><a href="/notizie">Notizie</a></h1>
    <div class="card-list">
        {
            news
                .sort((s, t) => -s.id.localeCompare(t.id))
                .map(newsItem => (
                    <div class="card">
                        <a href={`/notizie/${newsItem.slug}`} class="title">
                            {newsItem.data.title}
                        </a>
                        <div class="text small dimmed">
                            {new Date(newsItem.data.publishDate).toLocaleDateString('it-IT', {
                                year: 'numeric',
                                month: 'long',
                                day: 'numeric',
                            })}
                        </div>
                        <div class="text">{newsItem.data.description}</div>
                    </div>
                ))
        }
    </div>
</PageLayout>
