{"id":13452131,"url":"https://github.com/gusnips/gatsby-source-craftcms","last_synced_at":"2025-04-12T23:30:34.541Z","repository":{"id":57244938,"uuid":"138923997","full_name":"gusnips/gatsby-source-craftcms","owner":"gusnips","description":"Gatsby source plugin for building websites using the CraftCMS as a data source","archived":false,"fork":false,"pushed_at":"2019-01-22T22:55:34.000Z","size":111,"stargazers_count":19,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-11T08:22:16.474Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gusnips.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-27T19:23:44.000Z","updated_at":"2022-02-13T04:56:07.000Z","dependencies_parsed_at":"2022-09-01T04:31:13.528Z","dependency_job_id":null,"html_url":"https://github.com/gusnips/gatsby-source-craftcms","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gusnips%2Fgatsby-source-craftcms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gusnips%2Fgatsby-source-craftcms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gusnips%2Fgatsby-source-craftcms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gusnips%2Fgatsby-source-craftcms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gusnips","download_url":"https://codeload.github.com/gusnips/gatsby-source-craftcms/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647249,"owners_count":21139081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T07:01:14.103Z","updated_at":"2025-04-12T23:30:34.507Z","avatar_url":"https://github.com/gusnips.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# gatsby-source-craftcms\n\n## deprecated\nUse https://www.gatsbyjs.org/packages/gatsby-source-graphql/ instead\n  \n  \n  \n  \n### About\nSource plugin for pulling data into [Gatsby](https://github.com/gatsbyjs) from a [CraftCMS](https://craftcms.com) endpoint  \nBased on [gatsby-source-graphcms](https://github.com/GraphCMS/gatsby-source-graphcms)  \nTested in Gatsby v1 and v2\n\n### Install\n\n1. `yarn add gatsby-source-craftcms` or `npm i gatsby-source-craftcms`\n1. Make sure plugin is referenced in your Gatsby config, as in the\n   [example\u0026nbsp;below](#usage)\n1. `gatsby develop`\n\n### Usage\n\n_In your gatsby config..._\n\n```javascript\nplugins: [\n  {\n    resolve: `gatsby-source-craftcms`,\n    options: {\n      endpoint: `craftcms.mydomain.com/api`,\n      token: `graphql_token`,\n      query: `{\n          categories(site:\"default\",groupId:12) {\n              id\n              title\n              slug\n              uri\n          },\n          entries(section:[news],site:\"premium\") {\n            id\n            uri\n            title\n            slug\n          },\n          home: entries(section:[home],site:\"premium\") {\n            id\n            uri\n            title\n            slug\n          }\n      }`,\n    },\n  }\n],\n```\n\nGatsby’s data processing layer begins with “source” plugins, configured in `gatsby-config.js`. Here the site sources its data from the CraftCMS endpoint. Use an `.env` file or set environment variables directly to access the CraftCMS  \nendpoint and token. This avoids committing potentially sensitive data.  \n\n_In your gatsby-node.js ..._  \n\n```javascript\nconst path = require(\"path\");\n\nexports.createPages = ({ graphql, boundActionCreators }) =\u003e {\n  const { createPage } = boundActionCreators;\n\n  return new Promise((resolve, reject) =\u003e {\n    const postPage = path.resolve(\"src/templates/post.js\");\n    resolve(\n      graphql(`{\n        allEntry(sort: { fields: [postDate], order: DESC}){\n          edges {\n            news: node{\n              id\n              title\n              slug\n              postDate\n            }\n          }\n        }\n      }`).then(result =\u003e {\n        if (result.errors) {\n          reject(result.errors);\n        }\n        result.data.allEntry.edges.forEach(edge =\u003e {\n          createPage({\n            path: edge.news.slug,\n            component: postPage,\n            context: {\n              slug: edge.news.slug\n            }\n          });\n        });\n      })\n    );\n  });\n};\n\n```\n\n### Plugin options\n\n|              |                                                          |\n| -----------: | :------------------------------------------------------- |\n| **endpoint** | indicates the endpoint to use for the graphql connection |\n|    **token** | The API access token. Optional if the endpoint is public |\n|    **query** | The GraphQL query to execute against the endpoint        |\n\n### How to query : GraphQL\n\nLet’s say you have a GraphQL type called `Categories`. You would query all artists\nlike so:\n\n```graphql\n{\n  allCategory {\n    id\n    title\n}\n```\n\nentries example, to use in your template:  \n\n```javascript\nexport const pageQuery = graphql`\nquery GetPost($slug: String!) {\n  entry(slug: { eq: $slug }) {\n    id\n    slug\n    title\n    summary\n    uri\n    enableComments\n    contentPost {\n      block{\n        content\n        totalPages\n      }\n      quoteText\n      imagem{\n        url\n      }\n      titleH1\n      subtitleH2\n    }\n    category {\n      title\n      slug\n    }\n    tags{\n      title\n      slug\n    }\n  }\n}\n`;\n\n```\n\n### Testing plugin contributions\n\n1. `cd` to the Gatsby install you want to test your changes to the plugin code\n   with, or clone [@CraftCMS/gatsby-craftcms-example](https://github.com/gusnips/gatsby-craftcms-example)\n1. If you cloned the example or previously installed the plugin through `yarn`\n   or `npm`, `yarn remove gatsby-source-craftcms` or `npm r\n   gatsby-source-craftcms`\n1. `mkdir plugins` if it does not exist yet and `cd` into it\n1. Your path should now be something like\n   `~/code/gusnips/myKillerGatsbySite/plugins/`\n1. `git clone https://github.com/gusnips/gatsby-source-craftcms.git`\n1. `cd gatsby-source-craftcms`\n1. `yarn` or `yarn \u0026\u0026 yarn watch` in plugin’s directory for auto-rebuilding the\n   plugin after you make changes to it—only during development\n1. Make sure plugin is referenced in your Gatsby config, as in the\n   [example\u0026nbsp;below](#usage)\n1. From there you can `cd ../.. \u0026\u0026 yarn \u0026\u0026 yarn develop` to test\n\n#### Every time you rebuild the plugin, you must restart Gatsby’s development server to reflect the changes in your test environment.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgusnips%2Fgatsby-source-craftcms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgusnips%2Fgatsby-source-craftcms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgusnips%2Fgatsby-source-craftcms/lists"}