angrybeanie-front-end/pages/index.js
2021-02-04 14:27:14 +11:00

33 lines
No EOL
1.3 KiB
JavaScript

import Layout from "../components/main"
import LatestEpisodes from "../components/latestepisodes"
import Link from 'next/link'
import getConfig from 'next/config'
export async function getServerSideProps(context) {
const { serverRuntimeConfig, publicRuntimeConfig } = getConfig()
const res = await fetch(serverRuntimeConfig.base_path +`/api/collections/1`)
const artdata = await res.json()
const epres = await fetch(serverRuntimeConfig.base_path + '/api/podcasts/episodes/latest/0/3')
const epdata = await epres.json()
const secres = await fetch(serverRuntimeConfig.base_path + `/api/sections`)
const secdata = await secres.json()
const pagedata = {'title': 'Angry Beanie'}
return {
props: { articles: artdata, sections : secdata, pagedata, episodedata: epdata, config: serverRuntimeConfig}, // will be passed to the page component as props
}
}
function HomePage (props) {
return (<Layout sections={props.sections} pagedata={props.pagedata}>
{props.articles.articles.map((article) => (
<h1><Link href="/news/[slug]" as={"/news/" + article.slug}><a>{article.title}</a></Link></h1>
))}
<LatestEpisodes episodedata={props.episodedata} config={props.config}></LatestEpisodes>
</Layout>);
}
export default HomePage