29 lines
910 B
JavaScript
29 lines
910 B
JavaScript
|
|
import "../components/main"
|
||
|
|
import Layout from "../components/main"
|
||
|
|
import Link from 'next/link'
|
||
|
|
|
||
|
|
export async function getServerSideProps(context) {
|
||
|
|
const res = await fetch(`http://localhost:8000/api/documents/0/5`)
|
||
|
|
const articles = await res.json()
|
||
|
|
|
||
|
|
const secres = await fetch(`http://localhost:8000/api/sections`)
|
||
|
|
const secdata = await secres.json()
|
||
|
|
|
||
|
|
return {
|
||
|
|
props: { articles, sections : secdata }, // will be passed to the page component as props
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function News({ articles, sections }) {
|
||
|
|
return <Layout sections={sections}>
|
||
|
|
<h1>NEWS</h1>
|
||
|
|
{articles.articles.map((article) => (
|
||
|
|
<div>
|
||
|
|
<h1><Link href="/news/[slug]" as={"/news/" + article.slug}>{article.title}</Link></h1>
|
||
|
|
<div><html dangerouslySetInnerHTML={{__html: article.lead}} /></div>
|
||
|
|
</div>
|
||
|
|
))}
|
||
|
|
</Layout>
|
||
|
|
}
|
||
|
|
|
||
|
|
export default News
|