Skip to content

Instantly share code, notes, and snippets.

@tttimur
Last active June 10, 2020 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tttimur/72b9f93bab182dc80411221581eabf7c to your computer and use it in GitHub Desktop.
Save tttimur/72b9f93bab182dc80411221581eabf7c to your computer and use it in GitHub Desktop.
Prismic and next's demo
import { getPage } from '../api/prismic'
import Homempage from '../components/Homepage'
const Index = ({ page }) => <Homepage {...page} />
// to generate props during build time,
// can be replaced with getServerSideProps
Index.getStaticProps = async () => {
const page = await getPage('support')
return {
props: {
...page
}
}
}
export default Index
import Prismic from 'prismic-javascript'
const PRISMIC_API_URL = `https://XXXXXXX.cdn.prismic.io/api/v2`
export const getPage = async (page) => {
try {
const API = await Prismic.api(PRISMIC_API_URL)
const res = await API.getSingle(page, {
// used to reference fields within linked content
// for example when connecting an article (different post type)
// in a homepage, you can reference the article title (disabled by default)
fetchLinks: ['article.title', 'article.subtitle', 'article.slug'],
})
return {
status: 200,
page: res,
}
} catch (error) {
return {
error: error,
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment