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

37 lines
No EOL
1.1 KiB
JavaScript

import "../components/main"
import getConfig from 'next/config'
import Layout from "../components/main"
import StoryPager from "../components/storypager"
import Link from 'next/link'
import StorySideBar from "../components/storysidebar"
export async function getServerSideProps(context) {
if(context.query.page == null || context.query.page == '0') {
var page = 0;
} else {
var page = Number(context.query.page) - 1
}
const { serverRuntimeConfig, publicRuntimeConfig } = getConfig()
const res = await fetch(serverRuntimeConfig.base_path + `/api/documents/`+ page + `/5`)
const articles = await res.json()
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