import { useContext } from 'react';
import Markdown from 'markdown-to-jsx';

import { useSSG } from '.nextra/ssg';

export const getStaticProps = ({ params }) => {
  return (
    fetch('https://api.github.com/repos/formium/tsdx/releases')
      .then(res => res.json())
      // we keep the most recent 3 releases here
      .then(releases => ({ props: { ssg: releases.slice(0, 10) } }))
  );
};

export const ReleasesRenderer = () => {
  const releases = useSSG();
  return (
    <Markdown>
      {releases
        .map(release => {
          return `## <a href="${
            release.html_url
          }" target="_blank" rel="noopener">${
            release.tag_name
          }</a>\n\nPublished on ${new Date(
            release.published_at
          ).toDateString()}.\n\n${release.body}`;
        })
        .join('\n\n')}
    </Markdown>
  );
};

# Change Log

Please visit the [TSDX release page](https://github.com/formium/tsdx/releases) for all historical releases.

<ReleasesRenderer />
