├── .eslintignore ├── README.md ├── .gitignore ├── examples ├── arnaud │ ├── cypress.json │ ├── gatsby-node.js │ ├── src │ │ ├── images │ │ │ ├── gatsby-icon.png │ │ │ └── gatsby-astronaut.png │ │ ├── prismic │ │ │ └── linkResolver.js │ │ ├── pages │ │ │ ├── 404.js │ │ │ └── index.js │ │ └── components │ │ │ ├── header.js │ │ │ ├── blogpost.js │ │ │ ├── image.js │ │ │ ├── layout.js │ │ │ └── seo.js │ ├── cypress │ │ ├── fixtures │ │ │ └── example.json │ │ ├── integration │ │ │ └── arnaud.spec.js │ │ ├── support │ │ │ ├── index.js │ │ │ └── commands.js │ │ └── plugins │ │ │ └── index.js │ ├── gatsby-ssr.js │ ├── gatsby-browser.js │ ├── LICENSE │ ├── .gitignore │ ├── gatsby-config.js │ ├── package.json │ └── CHANGELOG.md ├── fragments │ ├── cypress.json │ ├── cypress │ │ ├── fixtures │ │ │ ├── profile.json │ │ │ └── example.json │ │ ├── integration │ │ │ └── fragments.spec.js │ │ ├── support │ │ │ ├── index.js │ │ │ └── commands.js │ │ └── plugins │ │ │ └── index.js │ ├── gatsby-node.js │ ├── src │ │ ├── images │ │ │ ├── gatsby-icon.png │ │ │ └── gatsby-astronaut.png │ │ ├── utils │ │ │ └── linkResolver.js │ │ ├── fragments │ │ │ └── ArticleFragment.js │ │ ├── pages │ │ │ ├── 404.js │ │ │ └── index.js │ │ └── components │ │ │ ├── header.js │ │ │ ├── articles.js │ │ │ ├── image.js │ │ │ ├── layout.js │ │ │ └── seo.js │ ├── gatsby-ssr.js │ ├── gatsby-browser.js │ ├── LICENSE │ ├── .gitignore │ ├── gatsby-config.js │ ├── package.json │ └── CHANGELOG.md ├── languages │ ├── cypress.json │ ├── gatsby-node.js │ ├── src │ │ ├── images │ │ │ ├── gatsby-icon.png │ │ │ └── gatsby-astronaut.png │ │ ├── utils │ │ │ └── linkResolver.js │ │ ├── pages │ │ │ └── 404.js │ │ ├── templates │ │ │ ├── article.js │ │ │ └── home.js │ │ └── components │ │ │ ├── header.js │ │ │ ├── image.js │ │ │ ├── layout.js │ │ │ └── seo.js │ ├── cypress │ │ ├── fixtures │ │ │ └── example.json │ │ ├── integration │ │ │ └── languages.spec.js │ │ ├── support │ │ │ ├── index.js │ │ │ └── commands.js │ │ └── plugins │ │ │ └── index.js │ ├── gatsby-ssr.js │ ├── gatsby-browser.js │ ├── LICENSE │ ├── .gitignore │ ├── package.json │ ├── gatsby-config.js │ └── CHANGELOG.md ├── pagination │ ├── cypress.json │ ├── gatsby-node.js │ ├── src │ │ ├── images │ │ │ ├── gatsby-icon.png │ │ │ └── gatsby-astronaut.png │ │ ├── utils │ │ │ └── linkResolver.js │ │ ├── pages │ │ │ ├── 404.js │ │ │ └── index.js │ │ ├── components │ │ │ ├── header.js │ │ │ ├── image.js │ │ │ ├── layout.js │ │ │ └── seo.js │ │ └── templates │ │ │ └── article.js │ ├── cypress │ │ ├── fixtures │ │ │ └── example.json │ │ ├── integration │ │ │ └── pagination.spec.js │ │ ├── support │ │ │ ├── index.js │ │ │ └── commands.js │ │ └── plugins │ │ │ └── index.js │ ├── gatsby-ssr.js │ ├── gatsby-browser.js │ ├── LICENSE │ ├── .gitignore │ ├── gatsby-config.js │ ├── package.json │ └── CHANGELOG.md ├── typescript │ ├── cypress.json │ ├── gatsby-node.js │ ├── src │ │ ├── images │ │ │ ├── gatsby-icon.png │ │ │ └── gatsby-astronaut.png │ │ ├── prismic │ │ │ └── linkResolver.ts │ │ ├── pages │ │ │ ├── 404.js │ │ │ ├── home.tsx │ │ │ └── index.tsx │ │ └── components │ │ │ ├── header.tsx │ │ │ ├── blogpost.js │ │ │ ├── image.tsx │ │ │ ├── layout.tsx │ │ │ └── seo.js │ ├── cypress │ │ ├── fixtures │ │ │ └── example.json │ │ ├── support │ │ │ ├── index.js │ │ │ └── commands.js │ │ ├── plugins │ │ │ └── index.js │ │ └── integration │ │ │ └── typescript.spec.js │ ├── gatsby-ssr.js │ ├── gatsby-browser.js │ ├── tsconfig.json │ ├── LICENSE │ ├── .gitignore │ ├── gatsby-config.js │ ├── CHANGELOG.md │ └── package.json ├── custom-path │ ├── cypress.json │ ├── gatsby-node.js │ ├── src │ │ ├── images │ │ │ ├── gatsby-icon.png │ │ │ └── gatsby-astronaut.png │ │ ├── prismic │ │ │ └── linkResolver.ts │ │ ├── pages │ │ │ ├── 404.js │ │ │ ├── home.tsx │ │ │ └── index.tsx │ │ └── components │ │ │ ├── header.tsx │ │ │ ├── blogpost.js │ │ │ ├── image.tsx │ │ │ ├── layout.tsx │ │ │ └── seo.js │ ├── cypress │ │ ├── fixtures │ │ │ └── example.json │ │ ├── integration │ │ │ └── custom-path.spec.js │ │ ├── support │ │ │ ├── index.js │ │ │ └── commands.js │ │ └── plugins │ │ │ └── index.js │ ├── gatsby-ssr.js │ ├── gatsby-browser.js │ ├── tsconfig.json │ ├── LICENSE │ ├── .gitignore │ ├── gatsby-config.js │ ├── CHANGELOG.md │ └── package.json └── static-query │ ├── cypress.json │ ├── gatsby-node.js │ ├── src │ ├── images │ │ ├── gatsby-icon.png │ │ └── gatsby-astronaut.png │ ├── utils │ │ └── linkResolver.js │ ├── pages │ │ └── index.js │ └── components │ │ ├── header.js │ │ ├── image.js │ │ ├── layout.js │ │ ├── articles.js │ │ └── seo.js │ ├── cypress │ ├── fixtures │ │ └── example.json │ ├── integration │ │ └── static-query.spec.js │ ├── support │ │ ├── index.js │ │ └── commands.js │ └── plugins │ │ └── index.js │ ├── gatsby-ssr.js │ ├── gatsby-browser.js │ ├── LICENSE │ ├── .gitignore │ ├── gatsby-config.js │ ├── package.json │ └── CHANGELOG.md ├── packages └── gatsby-source-prismic-graphql │ ├── .gitignore │ ├── src │ ├── interfaces │ │ ├── QueryStorage.ts │ │ ├── DocumentMetadata.ts │ │ ├── Dictionary.ts │ │ ├── PageOptions.ts │ │ └── PluginOptions.ts │ ├── index.ts │ ├── typings.d.ts │ ├── utils │ │ ├── url.ts │ │ ├── parseQueryString.ts │ │ ├── getApolloClient.ts │ │ ├── getIntrospectionQueryResultData.ts │ │ ├── createLoadingScreen.ts │ │ └── index.ts │ ├── components │ │ ├── withPreview.tsx │ │ ├── PreviewPage.tsx │ │ └── WrapPage.tsx │ ├── gatsby-browser.tsx │ └── gatsby-ssr.tsx │ ├── .editorconfig │ ├── .babelrc │ ├── tsconfig.json │ └── package.json ├── .travis.yml ├── .prettierignore ├── .editorconfig ├── lerna.json ├── CONTRIBUTING.md ├── LICENSE └── package.json /.eslintignore: -------------------------------------------------------------------------------- 1 | gatsby-source-prismic-graphql/**/*.js -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | packages/gatsby-source-prismic-graphql/README.md -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | .DS_Store 4 | .idea 5 | -------------------------------------------------------------------------------- /examples/arnaud/cypress.json: -------------------------------------------------------------------------------- 1 | { 2 | "baseUrl": "http://localhost:8000/", 3 | "video": false 4 | } 5 | -------------------------------------------------------------------------------- /examples/fragments/cypress.json: -------------------------------------------------------------------------------- 1 | { 2 | "baseUrl": "http://localhost:8000/", 3 | "video": false 4 | } 5 | -------------------------------------------------------------------------------- /examples/languages/cypress.json: -------------------------------------------------------------------------------- 1 | { 2 | "baseUrl": "http://localhost:8000/", 3 | "video": false 4 | } 5 | -------------------------------------------------------------------------------- /examples/pagination/cypress.json: -------------------------------------------------------------------------------- 1 | { 2 | "baseUrl": "http://localhost:8000/", 3 | "video": false 4 | } 5 | -------------------------------------------------------------------------------- /examples/typescript/cypress.json: -------------------------------------------------------------------------------- 1 | { 2 | "baseUrl": "http://localhost:8000/", 3 | "video": false 4 | } 5 | -------------------------------------------------------------------------------- /packages/gatsby-source-prismic-graphql/.gitignore: -------------------------------------------------------------------------------- 1 | *.js 2 | ./utils/*.js 3 | ./interfaces/*.js 4 | types 5 | -------------------------------------------------------------------------------- /examples/custom-path/cypress.json: -------------------------------------------------------------------------------- 1 | { 2 | "baseUrl": "http://localhost:8000/", 3 | "video": false 4 | } 5 | -------------------------------------------------------------------------------- /examples/static-query/cypress.json: -------------------------------------------------------------------------------- 1 | { 2 | "baseUrl": "http://localhost:8000/", 3 | "video": false 4 | } 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - node 4 | addons: 5 | apt: 6 | packages: 7 | - libgconf-2-4 -------------------------------------------------------------------------------- /packages/gatsby-source-prismic-graphql/src/interfaces/QueryStorage.ts: -------------------------------------------------------------------------------- 1 | export interface QueryStorage { 2 | query?: string; 3 | } 4 | -------------------------------------------------------------------------------- /examples/fragments/cypress/fixtures/profile.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": 8739, 3 | "name": "Jane", 4 | "email": "jane@example.com" 5 | } 6 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | .cache 2 | node_modules 3 | public 4 | packages/gatsby-source-prismic-graphql/**/*.js 5 | packages/gatsby-source-prismic-graphql/types/* -------------------------------------------------------------------------------- /examples/arnaud/gatsby-node.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's Node APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/node-apis/ 5 | */ 6 | -------------------------------------------------------------------------------- /examples/arnaud/src/images/gatsby-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/gatsby-source-prismic-graphql/master/examples/arnaud/src/images/gatsby-icon.png -------------------------------------------------------------------------------- /examples/custom-path/gatsby-node.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's Node APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/node-apis/ 5 | */ 6 | -------------------------------------------------------------------------------- /examples/fragments/gatsby-node.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's Node APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/node-apis/ 5 | */ 6 | -------------------------------------------------------------------------------- /examples/languages/gatsby-node.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's Node APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/node-apis/ 5 | */ 6 | -------------------------------------------------------------------------------- /examples/pagination/gatsby-node.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's Node APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/node-apis/ 5 | */ 6 | -------------------------------------------------------------------------------- /examples/static-query/gatsby-node.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's Node APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/node-apis/ 5 | */ 6 | -------------------------------------------------------------------------------- /examples/typescript/gatsby-node.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's Node APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/node-apis/ 5 | */ 6 | -------------------------------------------------------------------------------- /packages/gatsby-source-prismic-graphql/src/interfaces/DocumentMetadata.ts: -------------------------------------------------------------------------------- 1 | export interface DocumentMetadata { 2 | uid?: string; 3 | lang?: string; 4 | } 5 | -------------------------------------------------------------------------------- /examples/fragments/src/images/gatsby-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/gatsby-source-prismic-graphql/master/examples/fragments/src/images/gatsby-icon.png -------------------------------------------------------------------------------- /examples/languages/src/images/gatsby-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/gatsby-source-prismic-graphql/master/examples/languages/src/images/gatsby-icon.png -------------------------------------------------------------------------------- /examples/arnaud/src/images/gatsby-astronaut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/gatsby-source-prismic-graphql/master/examples/arnaud/src/images/gatsby-astronaut.png -------------------------------------------------------------------------------- /examples/custom-path/src/images/gatsby-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/gatsby-source-prismic-graphql/master/examples/custom-path/src/images/gatsby-icon.png -------------------------------------------------------------------------------- /examples/pagination/src/images/gatsby-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/gatsby-source-prismic-graphql/master/examples/pagination/src/images/gatsby-icon.png -------------------------------------------------------------------------------- /examples/static-query/src/images/gatsby-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/gatsby-source-prismic-graphql/master/examples/static-query/src/images/gatsby-icon.png -------------------------------------------------------------------------------- /examples/typescript/src/images/gatsby-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/gatsby-source-prismic-graphql/master/examples/typescript/src/images/gatsby-icon.png -------------------------------------------------------------------------------- /examples/fragments/src/images/gatsby-astronaut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/gatsby-source-prismic-graphql/master/examples/fragments/src/images/gatsby-astronaut.png -------------------------------------------------------------------------------- /examples/languages/src/images/gatsby-astronaut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/gatsby-source-prismic-graphql/master/examples/languages/src/images/gatsby-astronaut.png -------------------------------------------------------------------------------- /examples/custom-path/src/images/gatsby-astronaut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/gatsby-source-prismic-graphql/master/examples/custom-path/src/images/gatsby-astronaut.png -------------------------------------------------------------------------------- /examples/pagination/src/images/gatsby-astronaut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/gatsby-source-prismic-graphql/master/examples/pagination/src/images/gatsby-astronaut.png -------------------------------------------------------------------------------- /examples/static-query/src/images/gatsby-astronaut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/gatsby-source-prismic-graphql/master/examples/static-query/src/images/gatsby-astronaut.png -------------------------------------------------------------------------------- /examples/typescript/src/images/gatsby-astronaut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prismicio/gatsby-source-prismic-graphql/master/examples/typescript/src/images/gatsby-astronaut.png -------------------------------------------------------------------------------- /examples/arnaud/cypress/fixtures/example.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Using fixtures to represent data", 3 | "email": "hello@cypress.io", 4 | "body": "Fixtures are a great way to mock data for responses to routes" 5 | } 6 | -------------------------------------------------------------------------------- /examples/fragments/cypress/fixtures/example.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Using fixtures to represent data", 3 | "email": "hello@cypress.io", 4 | "body": "Fixtures are a great way to mock data for responses to routes" 5 | } 6 | -------------------------------------------------------------------------------- /examples/languages/cypress/fixtures/example.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Using fixtures to represent data", 3 | "email": "hello@cypress.io", 4 | "body": "Fixtures are a great way to mock data for responses to routes" 5 | } 6 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | indent_size = 2 8 | indent_style = space 9 | insert_final_newline = true 10 | trim_trailing_whitespace = true -------------------------------------------------------------------------------- /examples/custom-path/cypress/fixtures/example.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Using fixtures to represent data", 3 | "email": "hello@cypress.io", 4 | "body": "Fixtures are a great way to mock data for responses to routes" 5 | } 6 | -------------------------------------------------------------------------------- /examples/pagination/cypress/fixtures/example.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Using fixtures to represent data", 3 | "email": "hello@cypress.io", 4 | "body": "Fixtures are a great way to mock data for responses to routes" 5 | } 6 | -------------------------------------------------------------------------------- /examples/static-query/cypress/fixtures/example.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Using fixtures to represent data", 3 | "email": "hello@cypress.io", 4 | "body": "Fixtures are a great way to mock data for responses to routes" 5 | } 6 | -------------------------------------------------------------------------------- /examples/typescript/cypress/fixtures/example.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Using fixtures to represent data", 3 | "email": "hello@cypress.io", 4 | "body": "Fixtures are a great way to mock data for responses to routes" 5 | } 6 | -------------------------------------------------------------------------------- /examples/fragments/src/utils/linkResolver.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | linkResolver(doc) { 3 | if (doc.type === 'article') { 4 | return `/article/${doc.uid}`; 5 | } 6 | 7 | return '/'; 8 | }, 9 | }; 10 | -------------------------------------------------------------------------------- /examples/languages/src/utils/linkResolver.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | linkResolver(doc) { 3 | if (doc.type === 'article') { 4 | return `/article/${doc.uid}`; 5 | } 6 | 7 | return '/'; 8 | }, 9 | }; 10 | -------------------------------------------------------------------------------- /examples/pagination/src/utils/linkResolver.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | linkResolver(doc) { 3 | if (doc.type === 'article') { 4 | return `/article/${doc.uid}`; 5 | } 6 | 7 | return '/'; 8 | }, 9 | }; 10 | -------------------------------------------------------------------------------- /examples/arnaud/gatsby-ssr.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's SSR (Server Side Rendering) APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/ssr-apis/ 5 | */ 6 | 7 | // You can delete this file if you're not using it 8 | -------------------------------------------------------------------------------- /examples/static-query/src/utils/linkResolver.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | linkResolver(doc) { 3 | if (doc.type === 'article') { 4 | return `/article/${doc.uid}`; 5 | } 6 | 7 | return '/'; 8 | }, 9 | }; 10 | -------------------------------------------------------------------------------- /packages/gatsby-source-prismic-graphql/src/interfaces/Dictionary.ts: -------------------------------------------------------------------------------- 1 | export interface Dictionary { 2 | [urlPattern: string]: { 3 | componentPath: string; 4 | previewQuery: string; 5 | customType?: string; 6 | }; 7 | } 8 | -------------------------------------------------------------------------------- /examples/custom-path/gatsby-ssr.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's SSR (Server Side Rendering) APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/ssr-apis/ 5 | */ 6 | 7 | // You can delete this file if you're not using it 8 | -------------------------------------------------------------------------------- /examples/custom-path/src/prismic/linkResolver.ts: -------------------------------------------------------------------------------- 1 | export const linkResolver = (doc: any) => { 2 | if (doc.type === 'blogpos') return `/foo/bar/${doc.uid}`; 3 | else if (doc.type === 'homepage') return `/`; 4 | else return '/'; 5 | }; 6 | -------------------------------------------------------------------------------- /examples/fragments/gatsby-ssr.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's SSR (Server Side Rendering) APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/ssr-apis/ 5 | */ 6 | 7 | // You can delete this file if you're not using it 8 | -------------------------------------------------------------------------------- /examples/languages/gatsby-ssr.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's SSR (Server Side Rendering) APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/ssr-apis/ 5 | */ 6 | 7 | // You can delete this file if you're not using it 8 | -------------------------------------------------------------------------------- /examples/pagination/gatsby-ssr.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's SSR (Server Side Rendering) APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/ssr-apis/ 5 | */ 6 | 7 | // You can delete this file if you're not using it 8 | -------------------------------------------------------------------------------- /examples/static-query/gatsby-ssr.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's SSR (Server Side Rendering) APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/ssr-apis/ 5 | */ 6 | 7 | // You can delete this file if you're not using it 8 | -------------------------------------------------------------------------------- /examples/typescript/gatsby-ssr.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's SSR (Server Side Rendering) APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/ssr-apis/ 5 | */ 6 | 7 | // You can delete this file if you're not using it 8 | -------------------------------------------------------------------------------- /examples/typescript/src/prismic/linkResolver.ts: -------------------------------------------------------------------------------- 1 | export const linkResolver = (doc: any) => { 2 | if (doc.type === 'blogpos') return `/blogpost/${doc.uid}`; 3 | else if (doc.type === 'homepage') return `/`; 4 | else return '/'; 5 | }; 6 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "npmClient": "yarn", 3 | "useWorkspaces": true, 4 | "packages": ["packages/*"], 5 | "version": "3.6.4", 6 | "command": { 7 | "publish": { 8 | "conventionalCommits": true 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /examples/arnaud/src/prismic/linkResolver.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | linkResolver(doc) { 3 | if (doc.type === 'blogpos') return `/blogpost/${doc.uid}`; 4 | else if (doc.type === 'homepage') return `/`; 5 | else return '/'; 6 | }, 7 | }; 8 | -------------------------------------------------------------------------------- /packages/gatsby-source-prismic-graphql/.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | indent_size = 2 8 | indent_style = space 9 | insert_final_newline = true 10 | trim_trailing_whitespace = true -------------------------------------------------------------------------------- /examples/fragments/src/fragments/ArticleFragment.js: -------------------------------------------------------------------------------- 1 | import { graphql } from 'gatsby'; 2 | 3 | export const ArticleFragment = graphql` 4 | fragment ArticleFragment on PRISMIC_Article { 5 | _meta { 6 | uid 7 | } 8 | title 9 | } 10 | `; 11 | -------------------------------------------------------------------------------- /examples/fragments/cypress/integration/fragments.spec.js: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | context('Fragments', () => { 4 | beforeEach(() => cy.visit('/')); 5 | 6 | it('should render the home page', () => { 7 | cy.get('main').contains('Articles count'); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /examples/static-query/cypress/integration/static-query.spec.js: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | context('Static Query', () => { 4 | beforeEach(() => cy.visit('/')); 5 | 6 | it('should render the home page', () => { 7 | cy.get('header').contains('Gatsby Default Starter'); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/gatsby-source-prismic-graphql/src/interfaces/PageOptions.ts: -------------------------------------------------------------------------------- 1 | export interface Data { 2 | [key: string]: any; 3 | } 4 | export interface PageOptions { 5 | pattern: string; 6 | component: string; 7 | customType?: string; 8 | context: { [key: string]: any }; 9 | params: { data: Data; [key: string]: any | Data }; 10 | } 11 | -------------------------------------------------------------------------------- /examples/static-query/src/pages/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Articles } from '../components/articles'; 3 | import Layout from '../components/layout'; 4 | 5 | export default function Home(props) { 6 | return ( 7 | 8 |
9 |

Hello

10 | 11 |
12 |
13 | ); 14 | } 15 | -------------------------------------------------------------------------------- /examples/arnaud/gatsby-browser.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's Browser APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/browser-apis/ 5 | */ 6 | 7 | // You can delete this file if you're not using it 8 | const { registerLinkResolver } = require('@prismicio/gatsby-source-prismic-graphql'); 9 | 10 | registerLinkResolver(require('./src/prismic/linkResolver').linkResolver); 11 | -------------------------------------------------------------------------------- /examples/fragments/gatsby-browser.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's Browser APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/browser-apis/ 5 | */ 6 | 7 | // You can delete this file if you're not using it 8 | const { registerLinkResolver } = require('@prismicio/gatsby-source-prismic-graphql'); 9 | 10 | registerLinkResolver(require('./src/utils/linkResolver').linkResolver); 11 | -------------------------------------------------------------------------------- /examples/languages/gatsby-browser.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's Browser APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/browser-apis/ 5 | */ 6 | 7 | // You can delete this file if you're not using it 8 | const { registerLinkResolver } = require('@prismicio/gatsby-source-prismic-graphql'); 9 | 10 | registerLinkResolver(require('./src/utils/linkResolver').linkResolver); 11 | -------------------------------------------------------------------------------- /examples/pagination/gatsby-browser.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's Browser APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/browser-apis/ 5 | */ 6 | 7 | // You can delete this file if you're not using it 8 | const { registerLinkResolver } = require('@prismicio/gatsby-source-prismic-graphql'); 9 | 10 | registerLinkResolver(require('./src/utils/linkResolver').linkResolver); 11 | -------------------------------------------------------------------------------- /examples/static-query/gatsby-browser.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's Browser APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/browser-apis/ 5 | */ 6 | 7 | // You can delete this file if you're not using it 8 | const { registerLinkResolver } = require('@prismicio/gatsby-source-prismic-graphql'); 9 | 10 | registerLinkResolver(require('./src/utils/linkResolver').linkResolver); 11 | -------------------------------------------------------------------------------- /examples/typescript/gatsby-browser.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's Browser APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/browser-apis/ 5 | */ 6 | 7 | // You can delete this file if you're not using it 8 | const { registerLinkResolver } = require('@prismicio/gatsby-source-prismic-graphql'); 9 | 10 | registerLinkResolver(require('./src/prismic/linkResolver').linkResolver); 11 | -------------------------------------------------------------------------------- /examples/custom-path/gatsby-browser.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's Browser APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/browser-apis/ 5 | */ 6 | 7 | // You can delete this file if you're not using it 8 | const { registerLinkResolver } = require('@prismicio/gatsby-source-prismic-graphql'); 9 | 10 | registerLinkResolver(require('./src/prismic/linkResolver').linkResolver); 11 | -------------------------------------------------------------------------------- /examples/arnaud/src/pages/404.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | import Layout from '../components/layout'; 4 | import SEO from '../components/seo'; 5 | 6 | const NotFoundPage = () => ( 7 | 8 | 9 |

NOT FOUND

10 |

You just hit a route that doesn't exist... the sadness.

11 |
12 | ); 13 | 14 | export default NotFoundPage; 15 | -------------------------------------------------------------------------------- /examples/typescript/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "./dist/", 4 | "sourceMap": true, 5 | "noImplicitAny": true, 6 | "module": "commonjs", 7 | "target": "esnext", 8 | "jsx": "react", 9 | "lib": ["dom", "es2015", "es2017"], 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "noEmit": true 13 | }, 14 | "include": ["./src/**/*"] 15 | } 16 | -------------------------------------------------------------------------------- /examples/custom-path/src/pages/404.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | import Layout from '../components/layout'; 4 | import SEO from '../components/seo'; 5 | 6 | const NotFoundPage = () => ( 7 | 8 | 9 |

NOT FOUND

10 |

You just hit a route that doesn't exist... the sadness.

11 |
12 | ); 13 | 14 | export default NotFoundPage; 15 | -------------------------------------------------------------------------------- /examples/custom-path/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "./dist/", 4 | "sourceMap": true, 5 | "noImplicitAny": true, 6 | "module": "commonjs", 7 | "target": "esnext", 8 | "jsx": "react", 9 | "lib": ["dom", "es2015", "es2017"], 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "noEmit": true 13 | }, 14 | "include": ["./src/**/*"] 15 | } 16 | -------------------------------------------------------------------------------- /examples/fragments/src/pages/404.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | import Layout from '../components/layout'; 4 | import SEO from '../components/seo'; 5 | 6 | const NotFoundPage = () => ( 7 | 8 | 9 |

NOT FOUND

10 |

You just hit a route that doesn't exist... the sadness.

11 |
12 | ); 13 | 14 | export default NotFoundPage; 15 | -------------------------------------------------------------------------------- /examples/languages/src/pages/404.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | import Layout from '../components/layout'; 4 | import SEO from '../components/seo'; 5 | 6 | const NotFoundPage = () => ( 7 | 8 | 9 |

NOT FOUND

10 |

You just hit a route that doesn't exist... the sadness.

11 |
12 | ); 13 | 14 | export default NotFoundPage; 15 | -------------------------------------------------------------------------------- /examples/pagination/src/pages/404.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | import Layout from '../components/layout'; 4 | import SEO from '../components/seo'; 5 | 6 | const NotFoundPage = () => ( 7 | 8 | 9 |

NOT FOUND

10 |

You just hit a route that doesn't exist... the sadness.

11 |
12 | ); 13 | 14 | export default NotFoundPage; 15 | -------------------------------------------------------------------------------- /examples/typescript/src/pages/404.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | import Layout from '../components/layout'; 4 | import SEO from '../components/seo'; 5 | 6 | const NotFoundPage = () => ( 7 | 8 | 9 |

NOT FOUND

10 |

You just hit a route that doesn't exist... the sadness.

11 |
12 | ); 13 | 14 | export default NotFoundPage; 15 | -------------------------------------------------------------------------------- /packages/gatsby-source-prismic-graphql/src/index.ts: -------------------------------------------------------------------------------- 1 | export { default as PreviewPage } from './components/PreviewPage'; 2 | export { WrapPage } from './components/WrapPage'; 3 | export { withPreview } from './components/withPreview'; 4 | export { 5 | PrismicLink, 6 | getCookies, 7 | getCursorFromDocumentIndex, 8 | getDocumentIndexFromCursor, 9 | registerLinkResolver, 10 | linkResolver, 11 | fieldName, 12 | typeName, 13 | } from './utils'; 14 | -------------------------------------------------------------------------------- /packages/gatsby-source-prismic-graphql/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-env", 4 | "@babel/react", 5 | "@babel/preset-typescript" 6 | ], 7 | "plugins": [ 8 | ["@babel/plugin-transform-runtime", 9 | { 10 | "corejs": false, 11 | "helpers": true, 12 | "regenerator": true, 13 | "useESModules": false 14 | }], 15 | "@babel/proposal-class-properties", 16 | "@babel/proposal-object-rest-spread" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /examples/languages/cypress/integration/languages.spec.js: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | context('Languages', () => { 4 | beforeEach(() => cy.visit('/')); 5 | 6 | it('should render the home page', () => { 7 | cy.get('main').contains('A heading here'); 8 | cy.get('main').contains('Click here for alternative language'); 9 | }); 10 | 11 | it('should render another language', () => { 12 | cy.visit('http://localhost:8000/is'); 13 | cy.get('main').contains('Hver við erum og hver við viljum verða'); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /packages/gatsby-source-prismic-graphql/src/typings.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'jsonfn' { 2 | namespace JSONfn { 3 | function parse(str: string): any; 4 | function stringify(fn: any): any; 5 | } 6 | } 7 | 8 | declare module '@prismicio/gatsby-source-graphql-universal/gatsby-node' { 9 | function sourceNodes(ref: any, options: any): any; 10 | function onCreateWebpackConfig(): void; 11 | function getRootQuery(path: string): string | null; 12 | } 13 | 14 | declare module 'gatsby/dist/utils/babel-parse-to-ast'; 15 | 16 | declare module '@prismicio/gatsby-source-graphql-universal/getRootQuery'; 17 | -------------------------------------------------------------------------------- /packages/gatsby-source-prismic-graphql/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "declarationDir": "types", 5 | "skipLibCheck": true, 6 | // Target latest version of ECMAScript. 7 | "target": "esnext", 8 | // Search under node_modules for non-relative imports. 9 | "moduleResolution": "node", 10 | // Enable strictest settings like strictNullChecks & noImplicitAny. 11 | "strict": true, 12 | // Import non-ES modules as default imports. 13 | "esModuleInterop": true, 14 | // Types 15 | "types": ["node"], 16 | "jsx": "react" 17 | }, 18 | "include": ["src"] 19 | } 20 | -------------------------------------------------------------------------------- /examples/pagination/cypress/integration/pagination.spec.js: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | context('Pageination', () => { 4 | beforeEach(() => cy.visit('/')); 5 | 6 | it('should render the home page', () => { 7 | cy.get('main').contains('List of Articles'); 8 | cy.get('main').contains('The WordPress Question'); 9 | }); 10 | 11 | it('should render a next button', () => { 12 | const elem = cy.get('button').last(); 13 | elem.contains('next page'); 14 | }); 15 | 16 | it('should render another page', () => { 17 | cy.visit('/article/the-wordpress-question'); 18 | cy.get('main div h1').contains('The WordPress Question'); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /examples/arnaud/cypress/integration/arnaud.spec.js: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | context('Arnaud', () => { 4 | beforeEach(() => { 5 | cy.visit('/'); 6 | }); 7 | 8 | it('check header text', () => { 9 | cy.get('header').contains('Gatsby Default Starter'); 10 | }); 11 | 12 | it('check home page text', () => { 13 | cy.get('#homepage h1').contains('my homepage'); 14 | }); 15 | 16 | it('check first post', () => { 17 | cy.visit('/blogpost/published'); 18 | cy.get('main').contains('Published blogpost'); 19 | }); 20 | 21 | it('check second post', () => { 22 | cy.visit('/blogpost/published2'); 23 | cy.get('main').contains('published2'); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /examples/custom-path/cypress/integration/custom-path.spec.js: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | context('Custom path - we can create pages at a custom foo bar path', () => { 4 | beforeEach(() => { 5 | cy.visit('/'); 6 | }); 7 | 8 | it('check header text', () => { 9 | cy.get('header').contains('Gatsby Default Starter'); 10 | }); 11 | 12 | it('check home page text', () => { 13 | cy.get('#homepage h1').contains('my homepage'); 14 | }); 15 | 16 | it('check first post', () => { 17 | cy.visit('/Published%20blogpost/published'); 18 | cy.get('main').contains('Published blogpost'); 19 | }); 20 | 21 | it('check second post', () => { 22 | cy.visit('/published2/published2'); 23 | cy.get('main').contains('published2'); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /examples/arnaud/cypress/support/index.js: -------------------------------------------------------------------------------- 1 | // *********************************************************** 2 | // This example support/index.js is processed and 3 | // loaded automatically before your test files. 4 | // 5 | // This is a great place to put global configuration and 6 | // behavior that modifies Cypress. 7 | // 8 | // You can change the location of this file or turn off 9 | // automatically serving support files with the 10 | // 'supportFile' configuration option. 11 | // 12 | // You can read more here: 13 | // https://on.cypress.io/configuration 14 | // *********************************************************** 15 | 16 | // Import commands.js using ES2015 syntax: 17 | import './commands'; 18 | 19 | // Alternatively you can use CommonJS syntax: 20 | // require('./commands') 21 | -------------------------------------------------------------------------------- /examples/languages/src/templates/article.js: -------------------------------------------------------------------------------- 1 | import { graphql, Link } from 'gatsby'; 2 | import { linkResolver } from '@prismicio/gatsby-source-prismic-graphql'; 3 | import { RichText } from 'prismic-reactjs'; 4 | import React from 'react'; 5 | import Layout from '../components/layout'; 6 | 7 | export const query = graphql` 8 | query ArticleQuery($uid: String) { 9 | prismic { 10 | allArticles(uid: $uid) { 11 | edges { 12 | node { 13 | _meta { 14 | uid 15 | } 16 | } 17 | } 18 | } 19 | } 20 | } 21 | `; 22 | 23 | export default function Article(props) { 24 | return ( 25 | 26 |

Article

27 | Back to index 28 |
29 | ); 30 | } 31 | -------------------------------------------------------------------------------- /examples/custom-path/cypress/support/index.js: -------------------------------------------------------------------------------- 1 | // *********************************************************** 2 | // This example support/index.js is processed and 3 | // loaded automatically before your test files. 4 | // 5 | // This is a great place to put global configuration and 6 | // behavior that modifies Cypress. 7 | // 8 | // You can change the location of this file or turn off 9 | // automatically serving support files with the 10 | // 'supportFile' configuration option. 11 | // 12 | // You can read more here: 13 | // https://on.cypress.io/configuration 14 | // *********************************************************** 15 | 16 | // Import commands.js using ES2015 syntax: 17 | import './commands'; 18 | 19 | // Alternatively you can use CommonJS syntax: 20 | // require('./commands') 21 | -------------------------------------------------------------------------------- /examples/fragments/cypress/support/index.js: -------------------------------------------------------------------------------- 1 | // *********************************************************** 2 | // This example support/index.js is processed and 3 | // loaded automatically before your test files. 4 | // 5 | // This is a great place to put global configuration and 6 | // behavior that modifies Cypress. 7 | // 8 | // You can change the location of this file or turn off 9 | // automatically serving support files with the 10 | // 'supportFile' configuration option. 11 | // 12 | // You can read more here: 13 | // https://on.cypress.io/configuration 14 | // *********************************************************** 15 | 16 | // Import commands.js using ES2015 syntax: 17 | import './commands'; 18 | 19 | // Alternatively you can use CommonJS syntax: 20 | // require('./commands') 21 | -------------------------------------------------------------------------------- /examples/languages/cypress/support/index.js: -------------------------------------------------------------------------------- 1 | // *********************************************************** 2 | // This example support/index.js is processed and 3 | // loaded automatically before your test files. 4 | // 5 | // This is a great place to put global configuration and 6 | // behavior that modifies Cypress. 7 | // 8 | // You can change the location of this file or turn off 9 | // automatically serving support files with the 10 | // 'supportFile' configuration option. 11 | // 12 | // You can read more here: 13 | // https://on.cypress.io/configuration 14 | // *********************************************************** 15 | 16 | // Import commands.js using ES2015 syntax: 17 | import './commands'; 18 | 19 | // Alternatively you can use CommonJS syntax: 20 | // require('./commands') 21 | -------------------------------------------------------------------------------- /examples/pagination/cypress/support/index.js: -------------------------------------------------------------------------------- 1 | // *********************************************************** 2 | // This example support/index.js is processed and 3 | // loaded automatically before your test files. 4 | // 5 | // This is a great place to put global configuration and 6 | // behavior that modifies Cypress. 7 | // 8 | // You can change the location of this file or turn off 9 | // automatically serving support files with the 10 | // 'supportFile' configuration option. 11 | // 12 | // You can read more here: 13 | // https://on.cypress.io/configuration 14 | // *********************************************************** 15 | 16 | // Import commands.js using ES2015 syntax: 17 | import './commands'; 18 | 19 | // Alternatively you can use CommonJS syntax: 20 | // require('./commands') 21 | -------------------------------------------------------------------------------- /examples/static-query/cypress/support/index.js: -------------------------------------------------------------------------------- 1 | // *********************************************************** 2 | // This example support/index.js is processed and 3 | // loaded automatically before your test files. 4 | // 5 | // This is a great place to put global configuration and 6 | // behavior that modifies Cypress. 7 | // 8 | // You can change the location of this file or turn off 9 | // automatically serving support files with the 10 | // 'supportFile' configuration option. 11 | // 12 | // You can read more here: 13 | // https://on.cypress.io/configuration 14 | // *********************************************************** 15 | 16 | // Import commands.js using ES2015 syntax: 17 | import './commands'; 18 | 19 | // Alternatively you can use CommonJS syntax: 20 | // require('./commands') 21 | -------------------------------------------------------------------------------- /examples/typescript/cypress/support/index.js: -------------------------------------------------------------------------------- 1 | // *********************************************************** 2 | // This example support/index.js is processed and 3 | // loaded automatically before your test files. 4 | // 5 | // This is a great place to put global configuration and 6 | // behavior that modifies Cypress. 7 | // 8 | // You can change the location of this file or turn off 9 | // automatically serving support files with the 10 | // 'supportFile' configuration option. 11 | // 12 | // You can read more here: 13 | // https://on.cypress.io/configuration 14 | // *********************************************************** 15 | 16 | // Import commands.js using ES2015 syntax: 17 | import './commands'; 18 | 19 | // Alternatively you can use CommonJS syntax: 20 | // require('./commands') 21 | -------------------------------------------------------------------------------- /packages/gatsby-source-prismic-graphql/src/utils/url.ts: -------------------------------------------------------------------------------- 1 | import URLPattern from 'url-pattern'; 2 | 3 | export default { 4 | parse(pattern: string, urlPathname: string): { [key: string]: string } { 5 | const urlP = new URLPattern(pattern); 6 | return urlP.match(urlPathname) || {}; 7 | }, 8 | 9 | build(pattern: string, params: { [key: string]: string } = {}): string { 10 | return Object.keys(params).reduce((acc, key) => { 11 | return acc.replace(`:${key}`, params[key]); 12 | }, pattern); 13 | }, 14 | 15 | extractFixURL(urlPattern: string): string | undefined { 16 | var regex = /^(\/.*)*\/(:uid)/; 17 | 18 | const matched = urlPattern.match(regex); 19 | if (matched) { 20 | const [, fixURL] = matched; 21 | return fixURL; 22 | } 23 | }, 24 | }; 25 | -------------------------------------------------------------------------------- /examples/fragments/src/pages/index.js: -------------------------------------------------------------------------------- 1 | import { graphql } from 'gatsby'; 2 | import React from 'react'; 3 | import { Articles } from '../components/articles'; 4 | import Layout from '../components/layout'; 5 | import { ArticleFragment } from '../fragments/ArticleFragment'; 6 | 7 | export const query = graphql` 8 | query { 9 | prismic { 10 | allArticles(first: 3) { 11 | edges { 12 | node { 13 | ...ArticleFragment 14 | } 15 | } 16 | } 17 | } 18 | } 19 | `; 20 | 21 | export default function Home(props) { 22 | return ( 23 | 24 |
25 |

Articles count: {props.data.prismic.allArticles.edges.length}

26 | 27 |
28 |
29 | ); 30 | } 31 | 32 | Home.fragments = [ArticleFragment]; 33 | -------------------------------------------------------------------------------- /examples/arnaud/cypress/plugins/index.js: -------------------------------------------------------------------------------- 1 | /// 2 | // *********************************************************** 3 | // This example plugins/index.js can be used to load plugins 4 | // 5 | // You can change the location of this file or turn off loading 6 | // the plugins file with the 'pluginsFile' configuration option. 7 | // 8 | // You can read more here: 9 | // https://on.cypress.io/plugins-guide 10 | // *********************************************************** 11 | 12 | // This function is called when a project is opened or re-opened (e.g. due to 13 | // the project's config changing) 14 | 15 | /** 16 | * @type {Cypress.PluginConfig} 17 | */ 18 | module.exports = (on, config) => { 19 | // `on` is used to hook into various events Cypress emits 20 | // `config` is the resolved Cypress config 21 | }; 22 | -------------------------------------------------------------------------------- /examples/fragments/cypress/plugins/index.js: -------------------------------------------------------------------------------- 1 | /// 2 | // *********************************************************** 3 | // This example plugins/index.js can be used to load plugins 4 | // 5 | // You can change the location of this file or turn off loading 6 | // the plugins file with the 'pluginsFile' configuration option. 7 | // 8 | // You can read more here: 9 | // https://on.cypress.io/plugins-guide 10 | // *********************************************************** 11 | 12 | // This function is called when a project is opened or re-opened (e.g. due to 13 | // the project's config changing) 14 | 15 | /** 16 | * @type {Cypress.PluginConfig} 17 | */ 18 | module.exports = (on, config) => { 19 | // `on` is used to hook into various events Cypress emits 20 | // `config` is the resolved Cypress config 21 | }; 22 | -------------------------------------------------------------------------------- /examples/languages/cypress/plugins/index.js: -------------------------------------------------------------------------------- 1 | /// 2 | // *********************************************************** 3 | // This example plugins/index.js can be used to load plugins 4 | // 5 | // You can change the location of this file or turn off loading 6 | // the plugins file with the 'pluginsFile' configuration option. 7 | // 8 | // You can read more here: 9 | // https://on.cypress.io/plugins-guide 10 | // *********************************************************** 11 | 12 | // This function is called when a project is opened or re-opened (e.g. due to 13 | // the project's config changing) 14 | 15 | /** 16 | * @type {Cypress.PluginConfig} 17 | */ 18 | module.exports = (on, config) => { 19 | // `on` is used to hook into various events Cypress emits 20 | // `config` is the resolved Cypress config 21 | }; 22 | -------------------------------------------------------------------------------- /examples/custom-path/cypress/plugins/index.js: -------------------------------------------------------------------------------- 1 | /// 2 | // *********************************************************** 3 | // This example plugins/index.js can be used to load plugins 4 | // 5 | // You can change the location of this file or turn off loading 6 | // the plugins file with the 'pluginsFile' configuration option. 7 | // 8 | // You can read more here: 9 | // https://on.cypress.io/plugins-guide 10 | // *********************************************************** 11 | 12 | // This function is called when a project is opened or re-opened (e.g. due to 13 | // the project's config changing) 14 | 15 | /** 16 | * @type {Cypress.PluginConfig} 17 | */ 18 | module.exports = (on, config) => { 19 | // `on` is used to hook into various events Cypress emits 20 | // `config` is the resolved Cypress config 21 | }; 22 | -------------------------------------------------------------------------------- /examples/pagination/cypress/plugins/index.js: -------------------------------------------------------------------------------- 1 | /// 2 | // *********************************************************** 3 | // This example plugins/index.js can be used to load plugins 4 | // 5 | // You can change the location of this file or turn off loading 6 | // the plugins file with the 'pluginsFile' configuration option. 7 | // 8 | // You can read more here: 9 | // https://on.cypress.io/plugins-guide 10 | // *********************************************************** 11 | 12 | // This function is called when a project is opened or re-opened (e.g. due to 13 | // the project's config changing) 14 | 15 | /** 16 | * @type {Cypress.PluginConfig} 17 | */ 18 | module.exports = (on, config) => { 19 | // `on` is used to hook into various events Cypress emits 20 | // `config` is the resolved Cypress config 21 | }; 22 | -------------------------------------------------------------------------------- /examples/static-query/cypress/plugins/index.js: -------------------------------------------------------------------------------- 1 | /// 2 | // *********************************************************** 3 | // This example plugins/index.js can be used to load plugins 4 | // 5 | // You can change the location of this file or turn off loading 6 | // the plugins file with the 'pluginsFile' configuration option. 7 | // 8 | // You can read more here: 9 | // https://on.cypress.io/plugins-guide 10 | // *********************************************************** 11 | 12 | // This function is called when a project is opened or re-opened (e.g. due to 13 | // the project's config changing) 14 | 15 | /** 16 | * @type {Cypress.PluginConfig} 17 | */ 18 | module.exports = (on, config) => { 19 | // `on` is used to hook into various events Cypress emits 20 | // `config` is the resolved Cypress config 21 | }; 22 | -------------------------------------------------------------------------------- /examples/typescript/cypress/plugins/index.js: -------------------------------------------------------------------------------- 1 | /// 2 | // *********************************************************** 3 | // This example plugins/index.js can be used to load plugins 4 | // 5 | // You can change the location of this file or turn off loading 6 | // the plugins file with the 'pluginsFile' configuration option. 7 | // 8 | // You can read more here: 9 | // https://on.cypress.io/plugins-guide 10 | // *********************************************************** 11 | 12 | // This function is called when a project is opened or re-opened (e.g. due to 13 | // the project's config changing) 14 | 15 | /** 16 | * @type {Cypress.PluginConfig} 17 | */ 18 | module.exports = (on, config) => { 19 | // `on` is used to hook into various events Cypress emits 20 | // `config` is the resolved Cypress config 21 | }; 22 | -------------------------------------------------------------------------------- /packages/gatsby-source-prismic-graphql/src/interfaces/PluginOptions.ts: -------------------------------------------------------------------------------- 1 | export interface Page { 2 | type: string; 3 | match: string; 4 | previewPath?: string; 5 | component: string; 6 | langs?: string[]; 7 | sortBy?: string; 8 | filter?: Function; 9 | customPath?: (node: NodeType) => string; 10 | extraPageFields: string | string[]; 11 | } 12 | 13 | export interface PluginOptions { 14 | repositoryName: string; 15 | accessToken?: null | string; 16 | prismicRef?: null | string; 17 | linkResolver?: Function; 18 | defaultLang?: string; 19 | langs?: string[]; 20 | shortenUrlLangs?: boolean; 21 | passContextKeys?: string[]; 22 | previewPath?: string; 23 | previews?: boolean; 24 | pages?: Page[]; 25 | omitPrismicScript?: boolean; 26 | sharpKeys: RegExp[] | string[]; 27 | extraPageFields: string | string[]; 28 | } 29 | -------------------------------------------------------------------------------- /examples/custom-path/src/components/header.tsx: -------------------------------------------------------------------------------- 1 | import { Link } from 'gatsby'; 2 | import React, { FC } from 'react'; 3 | 4 | interface HeaderProps { 5 | siteTitle: string; 6 | } 7 | 8 | const Header: FC = ({ siteTitle }) => ( 9 |
15 |
22 |

23 | 30 | {siteTitle} 31 | 32 |

33 |
34 |
35 | ); 36 | 37 | export default Header; 38 | -------------------------------------------------------------------------------- /examples/typescript/src/components/header.tsx: -------------------------------------------------------------------------------- 1 | import { Link } from 'gatsby'; 2 | import React, { FC } from 'react'; 3 | 4 | interface HeaderProps { 5 | siteTitle: string; 6 | } 7 | 8 | const Header: FC = ({ siteTitle }) => ( 9 |
15 |
22 |

23 | 30 | {siteTitle} 31 | 32 |

33 |
34 |
35 | ); 36 | 37 | export default Header; 38 | -------------------------------------------------------------------------------- /packages/gatsby-source-prismic-graphql/src/utils/parseQueryString.ts: -------------------------------------------------------------------------------- 1 | export function parseQueryString(qs: string, delimiter: string = '&'): Map { 2 | if (!qs || qs.length == 0) return new Map(); 3 | 4 | return new Map( 5 | qs.split(delimiter).map(item => { 6 | const [key, ...value] = item.split('=').map(part => decodeURIComponent(part.trim())); 7 | return [key, value.join('=')] as [string, string]; 8 | }) 9 | ); 10 | } 11 | 12 | export function parseQueryStringAsJson( 13 | qs: string = '', 14 | delimiter: string = '&' 15 | ): { [key: string]: string } { 16 | const qsMap = parseQueryString(qs, delimiter); 17 | const qsMapIterator = qsMap[Symbol.iterator](); 18 | const qsJSON: { [key: string]: string } = {}; 19 | 20 | for (let item of qsMapIterator) { 21 | const keyJSON = item[0]; 22 | const value = item[1]; 23 | qsJSON[keyJSON] = value; 24 | } 25 | return qsJSON; 26 | } 27 | -------------------------------------------------------------------------------- /examples/arnaud/src/components/header.js: -------------------------------------------------------------------------------- 1 | import { Link } from 'gatsby'; 2 | import PropTypes from 'prop-types'; 3 | import React from 'react'; 4 | 5 | const Header = ({ siteTitle }) => ( 6 |
12 |
19 |

20 | 27 | {siteTitle} 28 | 29 |

30 |
31 |
32 | ); 33 | 34 | Header.propTypes = { 35 | siteTitle: PropTypes.string, 36 | }; 37 | 38 | Header.defaultProps = { 39 | siteTitle: ``, 40 | }; 41 | 42 | export default Header; 43 | -------------------------------------------------------------------------------- /examples/fragments/src/components/header.js: -------------------------------------------------------------------------------- 1 | import { Link } from 'gatsby'; 2 | import PropTypes from 'prop-types'; 3 | import React from 'react'; 4 | 5 | const Header = ({ siteTitle }) => ( 6 |
12 |
19 |

20 | 27 | {siteTitle} 28 | 29 |

30 |
31 |
32 | ); 33 | 34 | Header.propTypes = { 35 | siteTitle: PropTypes.string, 36 | }; 37 | 38 | Header.defaultProps = { 39 | siteTitle: ``, 40 | }; 41 | 42 | export default Header; 43 | -------------------------------------------------------------------------------- /examples/languages/src/components/header.js: -------------------------------------------------------------------------------- 1 | import { Link } from 'gatsby'; 2 | import PropTypes from 'prop-types'; 3 | import React from 'react'; 4 | 5 | const Header = ({ siteTitle }) => ( 6 |
12 |
19 |

20 | 27 | {siteTitle} 28 | 29 |

30 |
31 |
32 | ); 33 | 34 | Header.propTypes = { 35 | siteTitle: PropTypes.string, 36 | }; 37 | 38 | Header.defaultProps = { 39 | siteTitle: ``, 40 | }; 41 | 42 | export default Header; 43 | -------------------------------------------------------------------------------- /examples/pagination/src/components/header.js: -------------------------------------------------------------------------------- 1 | import { Link } from 'gatsby'; 2 | import PropTypes from 'prop-types'; 3 | import React from 'react'; 4 | 5 | const Header = ({ siteTitle }) => ( 6 |
12 |
19 |

20 | 27 | {siteTitle} 28 | 29 |

30 |
31 |
32 | ); 33 | 34 | Header.propTypes = { 35 | siteTitle: PropTypes.string, 36 | }; 37 | 38 | Header.defaultProps = { 39 | siteTitle: ``, 40 | }; 41 | 42 | export default Header; 43 | -------------------------------------------------------------------------------- /packages/gatsby-source-prismic-graphql/src/components/withPreview.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { WrapPage } from './WrapPage'; 3 | 4 | export const withPreview = ( 5 | render: (data: Data) => JSX.Element, 6 | query: any, 7 | fragments: any = [] 8 | ): ((data: Data) => JSX.Element) | null => { 9 | if (typeof window === 'undefined') { 10 | return render; 11 | } 12 | 13 | if (!render) { 14 | return null; 15 | } 16 | 17 | const RenderComponent = ({ data }: any) => render(data); 18 | const rootQuery = `${query.source}${fragments 19 | .map((fragment: any) => (fragment && fragment.source ? fragment.source : '')) 20 | .join(' ')}`; 21 | 22 | return (data: any) => ( 23 | 28 | 29 | 30 | ); 31 | }; 32 | -------------------------------------------------------------------------------- /examples/static-query/src/components/header.js: -------------------------------------------------------------------------------- 1 | import { Link } from 'gatsby'; 2 | import PropTypes from 'prop-types'; 3 | import React from 'react'; 4 | 5 | const Header = ({ siteTitle }) => ( 6 |
12 |
19 |

20 | 27 | {siteTitle} 28 | 29 |

30 |
31 |
32 | ); 33 | 34 | Header.propTypes = { 35 | siteTitle: PropTypes.string, 36 | }; 37 | 38 | Header.defaultProps = { 39 | siteTitle: ``, 40 | }; 41 | 42 | export default Header; 43 | -------------------------------------------------------------------------------- /examples/arnaud/cypress/support/commands.js: -------------------------------------------------------------------------------- 1 | // *********************************************** 2 | // This example commands.js shows you how to 3 | // create various custom commands and overwrite 4 | // existing commands. 5 | // 6 | // For more comprehensive examples of custom 7 | // commands please read more here: 8 | // https://on.cypress.io/custom-commands 9 | // *********************************************** 10 | // 11 | // 12 | // -- This is a parent command -- 13 | // Cypress.Commands.add("login", (email, password) => { ... }) 14 | // 15 | // 16 | // -- This is a child command -- 17 | // Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... }) 18 | // 19 | // 20 | // -- This is a dual command -- 21 | // Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... }) 22 | // 23 | // 24 | // -- This will overwrite an existing command -- 25 | // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) 26 | -------------------------------------------------------------------------------- /examples/custom-path/cypress/support/commands.js: -------------------------------------------------------------------------------- 1 | // *********************************************** 2 | // This example commands.js shows you how to 3 | // create various custom commands and overwrite 4 | // existing commands. 5 | // 6 | // For more comprehensive examples of custom 7 | // commands please read more here: 8 | // https://on.cypress.io/custom-commands 9 | // *********************************************** 10 | // 11 | // 12 | // -- This is a parent command -- 13 | // Cypress.Commands.add("login", (email, password) => { ... }) 14 | // 15 | // 16 | // -- This is a child command -- 17 | // Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... }) 18 | // 19 | // 20 | // -- This is a dual command -- 21 | // Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... }) 22 | // 23 | // 24 | // -- This will overwrite an existing command -- 25 | // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) 26 | -------------------------------------------------------------------------------- /examples/fragments/cypress/support/commands.js: -------------------------------------------------------------------------------- 1 | // *********************************************** 2 | // This example commands.js shows you how to 3 | // create various custom commands and overwrite 4 | // existing commands. 5 | // 6 | // For more comprehensive examples of custom 7 | // commands please read more here: 8 | // https://on.cypress.io/custom-commands 9 | // *********************************************** 10 | // 11 | // 12 | // -- This is a parent command -- 13 | // Cypress.Commands.add("login", (email, password) => { ... }) 14 | // 15 | // 16 | // -- This is a child command -- 17 | // Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... }) 18 | // 19 | // 20 | // -- This is a dual command -- 21 | // Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... }) 22 | // 23 | // 24 | // -- This will overwrite an existing command -- 25 | // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) 26 | -------------------------------------------------------------------------------- /examples/languages/cypress/support/commands.js: -------------------------------------------------------------------------------- 1 | // *********************************************** 2 | // This example commands.js shows you how to 3 | // create various custom commands and overwrite 4 | // existing commands. 5 | // 6 | // For more comprehensive examples of custom 7 | // commands please read more here: 8 | // https://on.cypress.io/custom-commands 9 | // *********************************************** 10 | // 11 | // 12 | // -- This is a parent command -- 13 | // Cypress.Commands.add("login", (email, password) => { ... }) 14 | // 15 | // 16 | // -- This is a child command -- 17 | // Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... }) 18 | // 19 | // 20 | // -- This is a dual command -- 21 | // Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... }) 22 | // 23 | // 24 | // -- This will overwrite an existing command -- 25 | // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) 26 | -------------------------------------------------------------------------------- /examples/pagination/cypress/support/commands.js: -------------------------------------------------------------------------------- 1 | // *********************************************** 2 | // This example commands.js shows you how to 3 | // create various custom commands and overwrite 4 | // existing commands. 5 | // 6 | // For more comprehensive examples of custom 7 | // commands please read more here: 8 | // https://on.cypress.io/custom-commands 9 | // *********************************************** 10 | // 11 | // 12 | // -- This is a parent command -- 13 | // Cypress.Commands.add("login", (email, password) => { ... }) 14 | // 15 | // 16 | // -- This is a child command -- 17 | // Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... }) 18 | // 19 | // 20 | // -- This is a dual command -- 21 | // Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... }) 22 | // 23 | // 24 | // -- This will overwrite an existing command -- 25 | // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) 26 | -------------------------------------------------------------------------------- /examples/static-query/cypress/support/commands.js: -------------------------------------------------------------------------------- 1 | // *********************************************** 2 | // This example commands.js shows you how to 3 | // create various custom commands and overwrite 4 | // existing commands. 5 | // 6 | // For more comprehensive examples of custom 7 | // commands please read more here: 8 | // https://on.cypress.io/custom-commands 9 | // *********************************************** 10 | // 11 | // 12 | // -- This is a parent command -- 13 | // Cypress.Commands.add("login", (email, password) => { ... }) 14 | // 15 | // 16 | // -- This is a child command -- 17 | // Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... }) 18 | // 19 | // 20 | // -- This is a dual command -- 21 | // Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... }) 22 | // 23 | // 24 | // -- This will overwrite an existing command -- 25 | // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) 26 | -------------------------------------------------------------------------------- /examples/typescript/cypress/support/commands.js: -------------------------------------------------------------------------------- 1 | // *********************************************** 2 | // This example commands.js shows you how to 3 | // create various custom commands and overwrite 4 | // existing commands. 5 | // 6 | // For more comprehensive examples of custom 7 | // commands please read more here: 8 | // https://on.cypress.io/custom-commands 9 | // *********************************************** 10 | // 11 | // 12 | // -- This is a parent command -- 13 | // Cypress.Commands.add("login", (email, password) => { ... }) 14 | // 15 | // 16 | // -- This is a child command -- 17 | // Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... }) 18 | // 19 | // 20 | // -- This is a dual command -- 21 | // Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... }) 22 | // 23 | // 24 | // -- This will overwrite an existing command -- 25 | // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) 26 | -------------------------------------------------------------------------------- /examples/languages/src/templates/home.js: -------------------------------------------------------------------------------- 1 | import { Link, graphql } from 'gatsby'; 2 | import React from 'react'; 3 | import Layout from '../components/layout'; 4 | import get from 'lodash/get'; 5 | import { RichText } from 'prismic-reactjs'; 6 | 7 | export const query = graphql` 8 | query Homepage($id: String) { 9 | prismic { 10 | allHomepages(id: $id) { 11 | edges { 12 | node { 13 | _meta { 14 | id 15 | lang 16 | } 17 | column_title 18 | } 19 | } 20 | } 21 | } 22 | } 23 | `; 24 | 25 | export default function Home(props) { 26 | const title = get(props.data, 'prismic.allHomepages.edges.0.node.column_title', []); 27 | const lang = get(props.pageContext, 'alternateLanguages.0.lang', '').replace('en-us', ''); 28 | 29 | return ( 30 | 31 | {RichText.render(title)} 32 | Click here for alternative language 33 | 34 | ); 35 | } 36 | -------------------------------------------------------------------------------- /packages/gatsby-source-prismic-graphql/src/gatsby-browser.tsx: -------------------------------------------------------------------------------- 1 | import { StaticQuery } from 'gatsby'; 2 | import PropTypes from 'prop-types'; 3 | import React from 'react'; 4 | import { WrapPage } from './components/WrapPage'; 5 | 6 | // Fixes proptypes warning for StaticQuery 7 | if (StaticQuery && typeof StaticQuery === 'object' && (StaticQuery as any).propTypes) { 8 | (StaticQuery as any).propTypes.query = PropTypes.oneOfType([ 9 | PropTypes.string, 10 | PropTypes.shape({ 11 | id: PropTypes.string, 12 | source: PropTypes.string, 13 | }), 14 | ]); 15 | } 16 | 17 | interface WrapPageArgs { 18 | element: any; 19 | props: any; 20 | } 21 | 22 | export const wrapPageElement = ({ element, props }: WrapPageArgs, options: any) => { 23 | if (props.pageContext.rootQuery || props.pageContext.prismicPreviewPage) { 24 | return ( 25 | 26 | {element} 27 | 28 | ); 29 | } 30 | 31 | return element; 32 | }; 33 | -------------------------------------------------------------------------------- /packages/gatsby-source-prismic-graphql/src/gatsby-ssr.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { PluginOptions } from './interfaces/PluginOptions'; 3 | 4 | interface OnRenderBodyArgs { 5 | setHeadComponents(args: React.ReactElement[]): void; 6 | } 7 | 8 | exports.onRenderBody = ({ setHeadComponents }: OnRenderBodyArgs, options: PluginOptions) => { 9 | const components = [ 10 |