Skip to content

Instantly share code, notes, and snippets.

@rshackleton
Last active May 11, 2020 12:05
Show Gist options
  • Save rshackleton/9b02bc716386dde1d4ee739259ba8995 to your computer and use it in GitHub Desktop.
Save rshackleton/9b02bc716386dde1d4ee739259ba8995 to your computer and use it in GitHub Desktop.
Get preview content with next.js
/**
* 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