在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):algolia/gatsby-plugin-algolia开源软件地址(OpenSource Url):https://github.com/algolia/gatsby-plugin-algolia开源编程语言(OpenSource Language):JavaScript 55.5%开源软件介绍(OpenSource Introduction):Gatsby plugin Algolia
You can specify a list of queries to run and how to transform them into an array of objects to index. When you run Here we have an example with some data that might not be very relevant, but will work with the default configuration of yarn add gatsby-plugin-algolia First 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. // .env.production
ALGOLIA_APP_ID=XXX
ALGOLIA_API_KEY=XXX
ALGOLIA_INDEX_NAME=XXX require('dotenv').config({
path: `.env.${process.env.NODE_ENV}`,
});
// gatsby-config.js
const myQuery = `
query {
pages: allSitePage {
nodes {
# querying id is required
id
component
path
componentChunkName
jsonName
internal {
# querying internal.contentDigest is required
contentDigest
type
owner
}
}
}
}
`;
const queries = [
{
query: myQuery,
queryVariables: {}, // optional. Allows you to use graphql query variables in the query
transformer: ({ data }) => data.pages.nodes, // optional
indexName: 'index name to target', // overrides main index name, optional
settings: {
// optional, any index settings
// Note: by supplying settings, you will overwrite all existing settings on the index
},
mergeSettings: false, // optional, defaults to false. See notes on mergeSettings below
},
];
module.exports = {
plugins: [
{
// This plugin must be placed last in your list of plugins to ensure that it can query all the GraphQL data
resolve: `gatsby-plugin-algolia`,
options: {
appId: process.env.ALGOLIA_APP_ID,
// Use Admin API key without GATSBY_ prefix, so that the key isn't exposed in the application
// Tip: use Search API key with GATSBY_ prefix to access the service from within components
apiKey: process.env.ALGOLIA_API_KEY,
indexName: process.env.ALGOLIA_INDEX_NAME, // for all queries
queries,
chunkSize: 10000, // default: 1000
settings: {
// optional, any index settings
// Note: by supplying settings, you will overwrite all existing settings on the index
},
mergeSettings: false, // optional, defaults to false. See notes on mergeSettings below
concurrentQueries: false, // default: true
dryRun: false, // default: false, only calculate which objects would be indexed, but do not push to Algolia
continueOnFailure: false, // default: false, don't fail the build if Algolia indexing fails
algoliasearchOptions: undefined, // default: { timeouts: { connect: 1, read: 30, write: 30 } }, pass any different options to the algoliasearch constructor
},
},
],
}; The index will be synchronised with the provided index name on Algolia on the Partial UpdatesThis plugin will update only the changed or deleted nodes on your Gatsby site. We rely on Gatsby's default SettingsYou can set settings for each index individually (per query), or otherwise it will keep your existing settings. Merge Settings
When set to true, the config index settings will be merged with the existing index settings in Algolia (with the config index settings taking precendence). NOTE: When using Concurrent QueriesSometimes, on limited platforms like Netlify, concurrent queries to the same index can lead to unexpected results or hanging builds. Setting TransformerThe FeedbackThis is the very first version of our plugin and isn't yet officially supported. Please leave all your feedback in GitHub issues |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论