angrybeanie-front-end/pages/news.js

34 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-12-06 21:49:37 +11:00
import "../components/main"
2021-02-04 14:27:14 +11:00
import getConfig from 'next/config'
2020-12-06 21:49:37 +11:00
import Layout from "../components/main"
2021-02-04 14:27:14 +11:00
import StoryPager from "../components/storypager"
import { getAllPosts } from "../data/external/cms"
2020-12-06 21:49:37 +11:00
export async function getServerSideProps(context) {
2021-02-04 14:27:14 +11:00
if(context.query.page == null || context.query.page == '0') {
var page = 1;
2021-02-04 14:27:14 +11:00
} else {
var page = Number(context.query.page)
2021-02-04 14:27:14 +11:00
}
const { serverRuntimeConfig, publicRuntimeConfig } = getConfig()
const articles = await getAllPosts(null, page, 5)
2020-12-06 21:49:37 +11:00
2021-02-04 14:27:14 +11:00
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 News'}
2020-12-06 21:49:37 +11:00
return {
2021-02-04 14:27:14 +11:00
props: { articles, sections : secdata, pagedata }, // 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 News({ articles, sections, pagedata }) {
return <Layout sections={sections} pagedata={pagedata}>
<h1 className="page_title col-sm-12">NEWS</h1>
2021-02-04 14:27:14 +11:00
<StoryPager storydata={articles} />
2020-12-06 21:49:37 +11:00
</Layout>
}
export default News