import { html, htmlToResponse } from "@mastrojs/mastro";
import { Layout } from "../components/Layout.ts";
import { readMarkdownFiles } from "@mastrojs/markdown";

export const GET = async () => {
  const posts = await readMarkdownFiles("data/posts/*.md");

  return htmlToResponse(
    Layout({
      title: "Home",
      children: html`
        <h2>About me</h2>
        <p>I am a (human) developer.</p>

        <h2>Posts</h2>
        <div class="post-list">
          ${posts.map(
            (post) => html`
              <a href="posts/${post.path.slice(12, -3) + "/"}">
                ${post.meta.title}
              </a>
            `,
          )}
        </div>
      `,
    }),
  );
};
