Last active
May 11, 2020 12:05
-
-
Save rshackleton/9b02bc716386dde1d4ee739259ba8995 to your computer and use it in GitHub Desktop.
Get preview content with next.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Execute server-side data fetching. | |
*/ | |
export const getStaticProps: GetStaticProps = async ({ params, preview }) => { | |
console.log(`Loading article content, preview mode is ${!!preview}`); | |
const slug = params?.slug as string; | |
const service = new ArticleService(preview ?? false); | |
const article = await service.getArticle(slug); | |
if (!article) { | |
return { props: {} }; | |
} | |
const props: IArticleProps = { | |
article: { | |
id: article.system.id, | |
codename: article.system.codename, | |
body: article.body.resolveHtml(), | |
slug: article.slug.value, | |
title: article.title.value, | |
metadata: { | |
title: article.metadata__page_title.value, | |
}, | |
}, | |
}; | |
return { props }; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment