From c333b3f392f308a718fa48dee78c1477aa6d8c88 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Sun, 20 Nov 2022 00:06:56 +0000 Subject: [PATCH] algolia test --- gatsby-config.ts | 3 ++ gatsby/algolia.ts | 89 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 gatsby/algolia.ts diff --git a/gatsby-config.ts b/gatsby-config.ts index 7352651e..ce780773 100644 --- a/gatsby-config.ts +++ b/gatsby-config.ts @@ -20,6 +20,8 @@ import { feedContent } from './gatsby/feeds' // required for gatsby-plugin-meta-redirect import 'regenerator-runtime/runtime' +//import algolia from './gatsby/algolia' + const config: GatsbyConfig = { graphqlTypegen: { typesOutputPath: './src/@types/Gatsby.d.ts', @@ -218,6 +220,7 @@ const config: GatsbyConfig = { 'gatsby-redirect-from', 'gatsby-plugin-meta-redirect', 'gatsby-plugin-offline' + // { ...algolia } ] } diff --git a/gatsby/algolia.ts b/gatsby/algolia.ts new file mode 100644 index 00000000..06a7afdf --- /dev/null +++ b/gatsby/algolia.ts @@ -0,0 +1,89 @@ +import * as dotenv from 'dotenv' + +dotenv.config() + +const myQuery = ` +{ + posts: allMarkdownRemark { + edges { + node { + id + excerpt + frontmatter { + title + image { + fields { + exif { + formatted { + iso + model + fstop + shutterspeed + focalLength + lensModel + exposure + gps { + latitude + longitude + } + } + } + } + } + toc + author + updated + tags + linkurl + style { + publicURL + } + changelog + } + fields { + type + slug + date + githubLink + } + rawMarkdownBody + } + } + } + } +` + +const queries = [ + { + query: myQuery, + // queryVariables: {}, // optional. Allows you to use graphql query variables in the query + transformer: ({ data }) => data.posts.edges.map(({ node }) => node), // 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 + } +] + +export default { + // 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, + apiKey: process.env.ALGOLIA_API_KEY, + indexName: process.env.ALGOLIA_INDEX_NAME, + 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 + } +}