This repository has been archived by the owner on May 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
655 additions
and
650 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,34 @@ | ||
// import React from 'react' | ||
// import { withUnpublishedPreview } from 'gatsby-source-prismic' | ||
// import { BlogPostTemplate } from '../templates/BlogPost' | ||
// // import { ProductTemplate } from '../templates/Product' | ||
import React from 'react' | ||
import { withUnpublishedPreview } from 'gatsby-source-prismic' | ||
import { BlogPostTemplate } from '../templates/blogPost' | ||
import { ProductTemplate } from '../templates/ourProduct' | ||
import { HomeTemplate } from './index' | ||
import { ProductsTemplate } from './products' | ||
import { BlogTemplate } from './blog' | ||
|
||
// const Page404 = () => ( | ||
// <div className="not-found"> | ||
// <h1>404</h1> | ||
// <h3>The page you are looking for was not found</h3> | ||
// <p> | ||
// <a href="/"> | ||
// <button type="button">Return to homepage</button> | ||
// </a> | ||
// </p> | ||
// </div> | ||
// ) | ||
const Page404 = () => ( | ||
<div className="not-found"> | ||
<h1>404</h1> | ||
<h3>The page you are looking for was not found</h3> | ||
<p> | ||
<a href="/"> | ||
<button type="button">Return to homepage</button> | ||
</a> | ||
</p> | ||
</div> | ||
) | ||
|
||
// export default withUnpublishedPreview(Page404, { | ||
// templateMap: { | ||
// // product: ProductTemplate, | ||
// blog_post: BlogPostTemplate, | ||
// // prismicProduct: ProductTemplate, | ||
// prismicBlogPost: BlogPostTemplate, | ||
// }, | ||
// }) | ||
export default withUnpublishedPreview(Page404, { | ||
templateMap: { | ||
homepage: HomeTemplate, | ||
product: ProductTemplate, | ||
products: ProductsTemplate, | ||
blog_post: BlogPostTemplate, | ||
blog_home: BlogTemplate, | ||
prismicHomepage: HomeTemplate, | ||
prismicProduct: ProductTemplate, | ||
prismicProducts: ProductsTemplate, | ||
prismicBlogPost: BlogPostTemplate, | ||
prismicBlogHome: BlogTemplate, | ||
}, | ||
}) |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,57 @@ | ||
import * as React from 'react' | ||
import { withPreviewResolver } from 'gatsby-source-prismic' | ||
import { graphql, useStaticQuery } from 'gatsby' | ||
import React, { useEffect } from 'react' | ||
import { navigate, useStaticQuery, graphql } from 'gatsby' | ||
import { usePrismicPreview } from 'gatsby-source-prismic' | ||
import { prismicRepo } from '../../prismic-configuration' | ||
|
||
import linkResolver from '../utils/linkResolver' | ||
|
||
const PreviewPage = ({ isPreview }) => { | ||
if (isPreview === false) return 'Not a preview!' | ||
|
||
return <p>Loading</p> | ||
} | ||
|
||
export default (props) => { | ||
const data = useStaticQuery(graphql` | ||
query { | ||
sitePlugin(name: { eq: "gatsby-source-prismic" }) { | ||
pluginOptions { | ||
repositoryName | ||
// Note that the `location` prop is taken and provided to the `usePrismicPreview` hook. | ||
const PreviewPage = ({ location }) => { | ||
// Let's use a static query to retrieve all known paths. We'll use it later | ||
// to navigate to the unpublishedPreview page if the document is not | ||
// published. | ||
const { allSitePage } = useStaticQuery(graphql` | ||
{ | ||
allSitePage { | ||
nodes { | ||
path | ||
} | ||
} | ||
} | ||
`) | ||
const { repositoryName } = data.sitePlugin.pluginOptions | ||
return withPreviewResolver(PreviewPage, { | ||
repositoryName, | ||
linkResolver: () => (doc) => linkResolver(doc), | ||
})(props) | ||
const allPaths = allSitePage.nodes.map((node) => node.path) | ||
|
||
const { isPreview, previewData, path } = usePrismicPreview({ | ||
// The repositoryName value from your `gatsby-config.js`. | ||
repositoryName: prismicRepo, | ||
}) | ||
|
||
// This useEffect runs when values from usePrismicPreview update. When | ||
// preview data is available, this will save the data globally and redirect to | ||
// the previewed document's page. | ||
useEffect(() => { | ||
// If this is not a preview, skip. | ||
// null = Not yet determined if previewing. | ||
// true = Preview is available. | ||
// false = Preview is not available. | ||
if (isPreview === false || !previewData) return | ||
|
||
// Save the preview data to somewhere globally accessible. This could be | ||
// something like a global Redux store or React context. | ||
// | ||
// We'll just put it on window. | ||
window.__PRISMIC_PREVIEW_DATA__ = previewData | ||
|
||
// Navigate to the document's page if page exists. | ||
if (allPaths.includes(path)) { | ||
navigate(path) | ||
} else { | ||
navigate('/unpublishedPreview') | ||
} | ||
}, [isPreview, previewData, path]) | ||
|
||
// Tell the user if this is not a preview. | ||
if (isPreview === false) return <div>Not a preview!</div> | ||
|
||
return <div>Loading preview...</div> | ||
} | ||
|
||
export default PreviewPage |
Oops, something went wrong.