{"id":13724471,"url":"https://github.com/algolia/gatsby-plugin-algolia","last_synced_at":"2025-04-04T06:10:02.211Z","repository":{"id":28441789,"uuid":"106009477","full_name":"algolia/gatsby-plugin-algolia","owner":"algolia","description":"A plugin to push to Algolia based on graphQl queries","archived":false,"fork":false,"pushed_at":"2023-11-02T10:08:56.000Z","size":789,"stargazers_count":179,"open_issues_count":11,"forks_count":45,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-14T05:02:32.825Z","etag":null,"topics":["algolia","gatsby","graphql","hacktoberfest","search","static-site-generator"],"latest_commit_sha":null,"homepage":"https://yarn.pm/gatsby-plugin-algolia","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/algolia.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-10-06T13:45:48.000Z","updated_at":"2024-11-13T07:24:02.000Z","dependencies_parsed_at":"2023-02-10T10:45:45.810Z","dependency_job_id":"805e25b9-a827-498b-a2c6-ce13713e0ee4","html_url":"https://github.com/algolia/gatsby-plugin-algolia","commit_stats":{"total_commits":147,"total_committers":33,"mean_commits":4.454545454545454,"dds":"0.34013605442176875","last_synced_commit":"c16a6e66f22f17272f1c1c624967764f188b290f"},"previous_names":[],"tags_count":54,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algolia%2Fgatsby-plugin-algolia","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algolia%2Fgatsby-plugin-algolia/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algolia%2Fgatsby-plugin-algolia/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algolia%2Fgatsby-plugin-algolia/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/algolia","download_url":"https://codeload.github.com/algolia/gatsby-plugin-algolia/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247128753,"owners_count":20888235,"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":["algolia","gatsby","graphql","hacktoberfest","search","static-site-generator"],"created_at":"2024-08-03T01:01:57.815Z","updated_at":"2025-04-04T06:10:02.190Z","avatar_url":"https://github.com/algolia.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Gatsby plugin Algolia\n\n\u003e This plugin is in _beta_ and not officially supported yet\n\u003e\n\u003e Feel free to open issues for any questions or ideas\n\nYou can specify a list of queries to run and how to transform them into an array of objects to index. When you run `gatsby build`, it will publish those to Algolia.\n\n```mermaid\ngraph LR\n    A[Source 1] --\u003e |query| Gatsby\n    B[Source 2] --\u003e |query| Gatsby\n    C[Source 3] --\u003e |query| Gatsby\n\n    Gatsby --\u003e |gatsby build| Algolia\n```\n\nHere we have an example with some data that might not be very relevant, but will work with the default configuration of `gatsby new`\n\n```shell\nyarn add gatsby-plugin-algolia\n```\n\nFirst add credentials to a .env file, which you won't commit. If you track this in your file, and especially if the site is open source, you will leak your admin API key. This would mean anyone is able to change anything on your Algolia index.\n\n```shell\n// .env.production\nALGOLIA_APP_ID=XXX\nALGOLIA_API_KEY=XXX\nALGOLIA_INDEX_NAME=XXX\n```\n\n```js\nrequire('dotenv').config({\n  path: `.env.${process.env.NODE_ENV}`,\n});\n\n// gatsby-config.js\nconst myQuery = `\n  query {\n    pages: allSitePage {\n      nodes {\n        # querying id is required\n        id\n        component\n        path\n        componentChunkName\n        jsonName\n        internal {\n          # querying internal.contentDigest is required\n          contentDigest\n          type\n          owner\n        }\n      }\n    }\n  }\n`;\n\nconst queries = [\n  {\n    query: myQuery,\n    queryVariables: {}, // optional. Allows you to use graphql query variables in the query\n    transformer: ({ data }) =\u003e data.pages.nodes, // optional\n    indexName: 'index name to target', // overrides main index name, optional\n    settings: {\n      // optional, any index settings\n      // Note: by supplying settings, you will overwrite all existing settings on the index\n    },\n    mergeSettings: false, // optional, defaults to false. See notes on mergeSettings below\n  },\n];\n\nmodule.exports = {\n  plugins: [\n    {\n      // This plugin must be placed last in your list of plugins to ensure that it can query all the GraphQL data\n      resolve: `gatsby-plugin-algolia`,\n      options: {\n        appId: process.env.ALGOLIA_APP_ID,\n        // Use Admin API key without GATSBY_ prefix, so that the key isn't exposed in the application\n        // Tip: use Search API key with GATSBY_ prefix to access the service from within components\n        apiKey: process.env.ALGOLIA_API_KEY,\n        indexName: process.env.ALGOLIA_INDEX_NAME, // for all queries\n        queries,\n        chunkSize: 10000, // default: 1000\n        settings: {\n          // optional, any index settings\n          // Note: by supplying settings, you will overwrite all existing settings on the index\n        },\n        mergeSettings: false, // optional, defaults to false. See notes on mergeSettings below\n        concurrentQueries: false, // default: true\n        dryRun: false, // default: false, only calculate which objects would be indexed, but do not push to Algolia\n        continueOnFailure: false, // default: false, don't fail the build if Algolia indexing fails\n        algoliasearchOptions: undefined, // default: { timeouts: { connect: 1, read: 30, write: 30 } }, pass any different options to the algoliasearch constructor\n      },\n    },\n  ],\n};\n```\n\nThe index will be synchronised with the provided index name on Algolia on the `build` step in Gatsby. This is not done earlier to prevent you going over quota while developing.\n\n## Partial Updates\n\nThis plugin will update only the changed or deleted nodes on your Gatsby site.\n\n**We rely on Gatsby's default `contentDigest` field, so make sure it is queried.**\n\n## Settings\n\nYou can set settings for each index individually (per query), or otherwise it will keep your existing settings.\n\n### Merge Settings\n\n`mergeSettings` allows you to preserve settings changes made on the Algolia website. The default behavior (`mergeSettings: false`) will wipe out your index settings and replace them with settings from the config on each build.\n\nWhen set to true, the config index settings will be merged with the existing index settings in Algolia (with the config index settings taking precendence).\n\nNOTE: When using `mergeSettings`, any **deleted** settings from the config settings will continue to be persisted since they will still exist in Algolia. If you want to remove a setting, be sure to remove it from both the config and on Algolia's website.\n\n## Concurrent Queries\n\nSometimes, on limited platforms like Netlify, concurrent queries to the same index can lead to unexpected results or hanging builds. Setting `concurrentQueries` to `false` makes it such that queries are run sequentially rather than concurrently, which may solve some concurrent access issues. Be aware that this option may make indexing take longer than it would otherwise.\n\n## Transformer\n\nThe `transformer` field accepts a function and optionally you may provide an `async` function.\n\nAdding a transformer parameter can be useful if the `internal.contentDigest` is more stable than your object. You can for example replace the Gatsby-provided `internal.contentDigest` with a hash of the object.\n\n```js\nconst crypto = require('crypto');\n\nfunction transformer(data) {\n  return data.map(item =\u003e {\n    const hash = crypto\n      .createHash('md5')\n      .update(JSON.stringify(item))\n      .digest('hex');\n\n    return {\n      ...item,\n      internal: {\n        ...item.internal,\n        contentDigest: hash,\n      },\n    };\n  });\n}\n```\n\n## Feedback\n\nThis is the very first version of our plugin and isn't yet officially supported. Please leave all your feedback in GitHub issues 😊\n\n## FAQ\n\n### Why do my updates not show up?\n\nThis could be happening for a few reasons:\n\n#### Development mode\n\nYou are using the `gatsby-plugin-algolia` plugin in development mode. The plugin will only push to Algolia when you run `gatsby build`. This is to prevent you from going over your quota while developing.\n\n#### Static `internal.contentDigest`\n\nSome Gatsby plugins don't create a new `internal.contentDigest`, even if the content has changed. To fix this, use a [`transformer`](#transformer) to create a new `internal.contentDigest` based on the content of the node.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falgolia%2Fgatsby-plugin-algolia","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falgolia%2Fgatsby-plugin-algolia","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falgolia%2Fgatsby-plugin-algolia/lists"}