---
import ArticleList from '../components/ArticleList.astro';
import ProjectList from '../components/ProjectList.astro';
import TagList from '../components/TagList.astro';
import Base from '../layouts/Base.astro';
import { buildPersonJsonLd, getAllTags, getArticles, getProjects } from '../lib/site';

const LATEST_ARTICLES = 5;

const posts = await getArticles();
const latestPosts = posts.slice(0, LATEST_ARTICLES);
const projects = await getProjects();
const selectedProjects = projects.filter((project) => project.data.project?.selected);
const tags = getAllTags(posts);

// Reference the canonical Person (defined on /about/) by @id.
const personJsonLd = buildPersonJsonLd();
---

<Base jsonLd={personJsonLd}>
  <section class="home-intro">
    <p class="eyebrow">Engineering notes</p>
    <h1>
      <span class="home-intro-name">Andras Schmelczer</span> sharing cool projects and lessons learned
    </h1>
    <p>
      I enjoy learning by building exciting things that sometimes even turn out to be useful. This page is dedicated to the projects I actually finished. To learn more about me, check out the <a href="/about/">About page</a>.
    </p>
  </section>

  <section class="home-section">
    <div class="section-heading">
      <h2 id="latest-articles">Latest Articles</h2>
      <a href="/articles/"
        >All {posts.length}
        {posts.length === 1 ? 'article' : 'articles'}
        <span aria-hidden="true">→</span></a
      >
    </div>
    <ArticleList posts={latestPosts} timeline eagerThumbnailCount={2} />
  </section>

  <section class="home-section">
    <div class="section-heading">
      <h2 id="home-selected-projects">Selected Projects</h2>
      <a href="/projects/">All projects <span aria-hidden="true">→</span></a>
    </div>
    <ProjectList projects={selectedProjects} />
  </section>

  <section class="home-section">
    <div class="section-heading">
      <h2 id="browse-by-topic">Browse by Topic</h2>
    </div>
    <div class="tag-cloud">
      <TagList tags={tags} />
    </div>
  </section>
</Base>
