
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
gatsby-source-sanity
Advanced tools
Gatsby source plugin for building websites using Sanity.io as a backend.
Source plugin for pulling data from Sanity.io into Gatsby websites.
yarn add gatsby-source-sanity
# or
npm i gatsby-source-sanity --save
// in your gatsby-config.js
module.exports = {
// ...
plugins: [
{
resolve: 'gatsby-source-sanity',
options: {
projectId: 'abc123',
dataset: 'blog',
token: process.env.MY_SANITY_TOKEN || 'my-token'
}
}
]
// ...
}
At this point you can choose to set up a GraphQL API for your Sanity dataset, if you have not done so already. This will help the plugin in knowing which types and fields exists, so you can query for them even without them being present in any current documents. It also helps create more sane names and types for the nodes in Gatsby.
Go through http://localhost:8000/___graphql after running gatsby develop
to understand the created data and create a new query and checking available collections and fields by typing CTRL + SPACE
.
Options | Type | Default | Description |
---|---|---|---|
projectId | string | [required] Your Sanity project's ID | |
dataset | string | [required] The dataset to fetch from | |
token | string | Authentication token for fetching data from private datasets, or when using overlayDrafts Learn more | |
overlayDrafts | boolean | false | Set to true in order for drafts to replace their published version. By default, drafts will be skipped. |
watchMode | boolean | false | Set to true to keep a listener open and update with the latest changes in realtime. |
If you don't want to attach your Sanity project's ID to the repo, you can easily store it in .env files by doing the following:
// In your .env file
SANITY_PROJECT_ID = abc123
SANITY_DATASET = production
SANITY_TOKEN = my-super-secret-token
// In your gatsby-config.js file
require('dotenv').config({
path: `.env.${process.env.NODE_ENV}`
})
module.exports = {
// ...
plugins: [
{
resolve: 'gatsby-source-sanity',
options: {
projectId: process.env.SANITY_PROJECT_ID,
dataset: process.env.SANITY_DATASET
token: process.env.SANITY_TOKEN
// ...
}
}
]
// ...
}
This example is based off Gatsby Docs' implementation.
The example below is for creating a slug field for your nodes.
// gatsby-node.js
const slugify = require('slugify')
exports.onCreateNode = ({node, actions}) => {
const {createNodeField} = actions
// check if the internal type corresponds to the type passed
// to the plugin in your gatsby-config.js
if (node.internal.type === 'Post') {
// the new field will be accessible as fields.slug
createNodeField({
node,
name: 'slug',
value: slugify(node.title, {lower: true})
})
}
}
Huge thanks to Henrique Cavalieri for doing the initial implementation of this plugin, and for donating it to the Sanity team. Mad props!
Big thanks to the good people backing Gatsby for bringing such a joy to our developer days!
FAQs
Gatsby source plugin for building websites using Sanity.io as a backend.
The npm package gatsby-source-sanity receives a total of 11,665 weekly downloads. As such, gatsby-source-sanity popularity was classified as popular.
We found that gatsby-source-sanity demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 42 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.