import Image from 'next/image'
import {Inter} from 'next/font/google'
import Link from "next/link";
const inter = Inter({subsets: ['latin']})
interface tHomeProps {
posts: number[],
formattedDate: string
}
export default function Home(props: tHomeProps) {
const {formattedDate} = props;
return (
Static (SSG) page
This page is static site generated page (SSG). It was built on {formattedDate}.
View a server-side rendered page (SSR).
This page demonstrates a SSG page where we pulled the data (list, detail) at the time of the build. Please click on each of the links.
List of Hacker News Post IDs from {formattedDate.slice(0,13)}
{props.posts.length > 0 && props.posts.map((postId: number) => (
-
https://news.ycombinator.com/item?id=/{postId}
))}
);
}
export async function getStaticProps() {
const buildDate = Date.now();
try {
const formattedDate = new Intl.DateTimeFormat("en-US", {
dateStyle: "long",
timeStyle: "long",
}).format(buildDate);
const res = await fetch('https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty');
const postIds: number[] = await res.json();
return {
props: {
posts: postIds,
formattedDate
}
};
} catch (e) {
console.log(e);
}
}