https://github.com/algolia/gatsby-plugin-algolia
我运行构建时此插件似乎在我的gatsby-config中不起作用(不填充我的algolia索引)-我已经使用algoliasearch和json文件将数据推入了我的索引中,但是我希望每次构建时都能自动连接它-因此数据始终与空气表数据保持最新。
我已经通过github上的文档(放在我的gatsby-config.js文件中)尝试了“ gatsby-plugin-algolia”方法
const myQuery = `{
allSitePage {
edges {
node {
# try to find a unique id for each node
# if this field is absent, it's going to
# be inserted by Algolia automatically
# and will be less simple to update etc.
objectID: id
component
path
componentChunkName
jsonName
internal {
type
contentDigest
owner
}
}
}
}
}`;
const queries = [
{
query: myQuery,
transformer: ({ data }) => data.allSitePage.edges.map(({ node }) => node),
indexName: 'cardDemo',
},
];
module.exports = {
plugins: [
{
resolve: 'gatsby-source-airtable-linked',
options: {
apiKey: process.env.MY_API_KEY,
tables: [
{
baseId: process.env.MY_BASE_ID,
tableName: 'Streams',
tableView: 'DO NOT MODIFY',
},
],
},
},
{
resolve: 'gatsby-plugin-algolia',
options: {
appId: process.env.MY_AGOLIA_APP_ID,
apiKey: process.env.MY_AGOLIA_API_KEY,
indexName: 'cardDemo',
queries,
chunkSize: 1000000,
},
},
],
};
我还通过airtable为我正在组件上使用的更具体的实例提供了'myQuery'的显示,如下所示
const myQuery = `{
items: allAirtableLinked(
filter: {
table: { eq: "Items" }
}
) {
edges {
node {
id
data {
title
thumbnail_url
thumbnail_alt_text
url_slug
uberflip_stream_id
uberflip_id
}
}
}
}
}`;
如果有人正在运行此插件,并且该插件可以正常工作,我肯定可以使用一些提示使其正常工作(此软件包上没有太多文档)
谢谢!
答案 0 :(得分:2)
弄清楚了!任何遇到此问题的人,请执行以下步骤:
transformer: ({ data }) => data.items.edges.map(({ node }) => node)
const pageQuery = `query {
items: allAirtableLinked(
filter: {
table: { eq: "Items" }
data: { hubs: { eq: "cf4ao8fjzn4xsRrD" } }
}
) {
edges {
node {
id
data {
title
thumbnail_url
thumbnail_alt_text
duration
url_slug
asset_type
uberflip_stream_id
uberflip_id
}
}
}
}
}`;
i got this idea from this repo, very helpful! check out this example