angrybeanie-front-end/pages/news.js
James Purser 25e70c36d4 Added Tech and Disability section to navigation and page
Refactored News to use the getAllPosts method in data/external/cms
2022-06-14 20:58:06 +10:00

34 lines
No EOL
1 KiB
JavaScript
Executable file

import "../components/main"
import getConfig from 'next/config'
import Layout from "../components/main"
import StoryPager from "../components/storypager"
import { getAllPosts } from "../data/external/cms"
export async function getServerSideProps(context) {
if(context.query.page == null || context.query.page == '0') {
var page = 1;
} else {
var page = Number(context.query.page)
}
const { serverRuntimeConfig, publicRuntimeConfig } = getConfig()
const articles = await getAllPosts(null, page, 5)
const secres = await fetch(serverRuntimeConfig.base_path + `/api/sections`)
const secdata = await secres.json()
const pagedata = {'title': 'Angry Beanie News'}
return {
props: { articles, sections : secdata, pagedata }, // will be passed to the page component as props
}
}
function News({ articles, sections, pagedata }) {
return <Layout sections={sections} pagedata={pagedata}>
<h1>NEWS</h1>
<StoryPager storydata={articles} />
</Layout>
}
export default News