Last active
June 10, 2020 16:28
-
-
Save tttimur/72b9f93bab182dc80411221581eabf7c to your computer and use it in GitHub Desktop.
Prismic and next's demo
This file contains 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
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 |
This file contains 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
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