gatsby-plugin-prismic-preview icon indicating copy to clipboard operation
gatsby-plugin-prismic-preview copied to clipboard

Not working out-of-the-box

Open scottlyttle opened this issue 6 years ago • 6 comments
trafficstars

I can't seem to get this plugin working out of the box. The preview button within Prismic correctly redirects to http://localhost:8000/preview?token=[etc] (/preview was set as the link resolver here) but the site eventually redirects back to the homepage at http://localhost:8000/?token=[etc]. I understand this may be something related to the linkResolver config for this module and I have tried several options to no avail. In the example folder of this module your link resolver is just '/'.

Do you have any suggestions on how this could be tackled? Is further configuration required?

scottlyttle avatar Nov 28 '18 09:11 scottlyttle

You need to configure the link resolver to redirect to the correct page.

If you have a blog post on /blog/foobar, the link resolver should check for the type and uid and redirect to the correct page.

What did you expect to happen?

birkir avatar Nov 28 '18 22:11 birkir

I'm using the createPage function to generate pages when Gatsby is run, so if the page is unpublished in Prismic the path is never generated. Even when the correct link resolver is set (/${doc.uid} on my particular site) it will still redirect to the homepage.

scottlyttle avatar Nov 29 '18 08:11 scottlyttle

Gotcha.

What I've done before is to create like a single page that serves as a "catch-all" page for previews where link resolver cannot find the correct page (unpublished, drafts, etc)

This page finds the most relevant page to use as a template for the preview and replaces the id of the template page with the previewable id.

Massive hack, but yeah I haven't figured this out yet in gatsby land.

birkir avatar Dec 06 '18 03:12 birkir

I've tried to set-up this plugin however I think I am doing something wrong.

This is my gatsby-config.js:

    {
      resolve: 'gatsby-plugin-prismic-preview',
      options: {
        repositoryName: 'test-project', // same as in gatsby-source-prismic
        linkResolver(doc) {
          console.log('hello, here the link resolver');
          console.log(doc);
          return `/test`;
        },
        path: '/preview',
      },
    },

I don't see any log nor it redirects to /test

PolGuixe avatar Jan 14 '19 12:01 PolGuixe

@PolGuixe I've found that the example of defining the function inline does not work as you've seen.

Using the require syntax from the other example, I do get fed to the correct page. Just trying to figure out what is left to get preview content to appear now...

joseph-cloudthing avatar Jan 22 '19 16:01 joseph-cloudthing

Anyone got this working?

like-vyk avatar Feb 15 '19 18:02 like-vyk