---
import { organizedEvents } from "../../data/events";

export function getStaticPaths() {
  const years = Array.from(new Set(organizedEvents.map((event) => event.year)));

  return years.map((year) => ({
    params: { year },
    props: { year },
  }));
}

type Props = {
  year: string;
};

const { year } = Astro.props;
const target = `/?year=${encodeURIComponent(year)}#events`;
---

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="robots" content="noindex" />
    <meta http-equiv="refresh" content={`0; url=${target}`} />
    <link rel="canonical" href={target} />
    <title>Redirecting to {year} events</title>
    <script is:inline define:vars={{ target }}>
      window.location.replace(target);
    </script>
  </head>
  <body>
    <p>Redirecting to <a href={target}>{year} events</a>.</p>
  </body>
</html>
