angrybeanie-front-end/pages/index.js

37 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-12-06 21:49:37 +11:00
import Layout from "../components/main"
2021-02-04 14:27:14 +11:00
import LatestEpisodes from "../components/latestepisodes"
2020-12-06 21:49:37 +11:00
import Link from 'next/link'
2021-02-04 14:27:14 +11:00
import getConfig from 'next/config'
2020-12-06 21:49:37 +11:00
2021-02-04 14:27:14 +11:00
export async function getServerSideProps(context) {
const { serverRuntimeConfig, publicRuntimeConfig } = getConfig()
const res = await fetch(serverRuntimeConfig.base_path +`/api/collections/1`)
2020-12-06 21:49:37 +11:00
const artdata = await res.json()
2021-02-04 14:27:14 +11:00
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`)
2020-12-06 21:49:37 +11:00
const secdata = await secres.json()
2021-02-04 14:27:14 +11:00
const pagedata = {'title': 'Angry Beanie'}
2020-12-06 21:49:37 +11:00
return {
2021-02-04 14:27:14 +11:00
props: { articles: artdata, sections : secdata, pagedata, episodedata: epdata, config: serverRuntimeConfig}, // will be passed to the page component as props
2020-12-06 21:49:37 +11:00
}
}
2021-02-04 14:27:14 +11:00
function HomePage (props) {
return (<Layout sections={props.sections} pagedata={props.pagedata}>
{props.articles.articles.map((article) => (
2021-09-05 16:12:45 +10:00
<div>
<h1><Link href="/news/[slug]" as={"/news/" + article.slug}><a>{article.title}</a></Link></h1>
<div dangerouslySetInnerHTML={{ __html: article.lead}} ></div>
</div>
2020-12-06 21:49:37 +11:00
))}
2021-09-05 16:12:45 +10:00
<hr />
2021-02-04 14:27:14 +11:00
<LatestEpisodes episodedata={props.episodedata} config={props.config}></LatestEpisodes>
2020-12-06 21:49:37 +11:00
</Layout>);
}
export default HomePage