Giter VIP home page Giter VIP logo

gatsby-plugin-stork's Introduction

Build npm version npm

gatsby-plugin-stork

This is a Gatsby plugin for generating a search engine using Stork. This plugin automatically generates a Stork search index from your site's content and includes it in your public directory. This plugin also automatically mounts the Stork script tag to the end of your HTML files.

Installation

To install, run npm i gatsby-plugin-stork. Once installed, add the plugin to your gatsby-config.js.

module.exports = {
    plugins: [
        "gatsby-plugin-stork",
    ]
}

You can also pass in additional options:

module.exports = {
    plugins: [
        {
          resolve: "gatsby-plugin-stork",
          options: {
            indexes: [
              {
                resolvers: {
                  Mdx: {
                    contents: node => node.rawBody,
                    url: node => node.fields.slug,
                    title: node => node.frontmatter.title
                  },
                },
                filename: "firstIndex.st"
              }
            ],
            theme: "dark"
          }
        }
    ]
}

The search bar can be mounted using the StorkInput component:

import React from 'react';
import { StorkInput } from 'gatsby-plugin-stork';

export const YourSearchComponent = () => {
  return (
    <StorkInput filename="firstIndex.st" placeholder="๐Ÿ”" />
  );
}

Configuration Options

indexes

This is an array of objects where each represents a separate index file. This object should have the following keys:

resolvers

resolvers is an object of node types, which in turn is a series of key-value pairs where each key is the name of a configuration option and the value is a function that takes in a node and returns the value for that option. For example, a common node type for blog posts is MarkdownRemark, and at a minimum, you must pass at least a url, title, and either a path or contents. Such a set of resolvers would look like this:

{
  resolvers: {
    MarkdownRemark: {
      contents: node => node.rawBody,
      url: node => node.fields.slug,
      title: node => node.frontmatter.title
    }
  },
  filename: "example.st",
}

filename

The name of the resulting index file. By default, it is called stork.st, but you may wish to call it something else.

theme

The name of the Stork theme to install. Setting this option to null will not install a theme.

Project Status

Note that this project is still pre-1.0, and minor version bumps may contain breaking changes. If you are still using this pre-1.0, I recommend pinning to a minor version.

Running During Automated Builds

If you use an automated build system as part of your site's deploy system, you'll need to have Stork installed as part of the build process for this plugin to run successfully. The docs have some instructions on setting Stork up with Netlify, but similar steps can be applied to any static site build runner.

This plugin will by default run the stork executable, but you can also supply a path to the executable with the GATSBY_STORK_EXECUTABLE_PATH environment variable to run Stork from a different installation.

gatsby-plugin-stork's People

Contributors

dependabot[bot] avatar reese avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

krischer

gatsby-plugin-stork's Issues

Bug: Undefined errors while attempting to create new index

Hi Reese @reese ,

Thank you so much for creating this plugin! ๐Ÿ‘ I was trying to use this in my Gatsby site, and was unfortunately running into few internal errors from the plugin.

This is my configuration for the gatsby plugin. I have ensured and validated from Gatsby's GraphQL explorer that the below fields exist correctly for nodes of type annotations:

    {
      resolve: "gatsby-plugin-stork",
      options: {
        indexes: [
          {
            resolvers: {
              annotations: {
                url: node => node.fields.book_slug_path,
                title: node => node.extracted_google_books_metadata.book_title,
                contents: node => node.extracted_google_books_metadata.book_description,
              }
            },
            filename: 'annotations.st'
          }
        ],
        theme: "dark",
      }
    }

And for some reason, i keep on running into this exception below - which seems related to this line:

 ERROR #11321  PLUGIN

"gatsby-plugin-stork" threw an error while running the onPostBootstrap lifecycle:

Cannot set property 'title' of undefined

  60 |                             var key = _ref6[0],
  61 |                                 resolveFunc = _ref6[1];
> 62 |                             acc[key] = resolveFunc(node);
     |                                      ^
  63 |                           }, {});
  64 |                           files.push(resolvedValues);
  65 |                         }); // Serialize and write to TOML

File: node_modules/gatsby-plugin-stork/gatsby-node.js:62:38



  TypeError: Cannot set property 'title' of undefined

I tried to oversimplify the config above to this subsequently, i.e, just hardcoded strings - and even then I'm running into the same exception as above. Surely if there was some issue with my nodes configuration above and if that might have been resulting in the exception above, then it should have succeeded here:

    {
      resolve: "gatsby-plugin-stork",
      options: {
        indexes: [
          {
            resolvers: {
              annotations: {
                url: node => "test1",
                title: node => "test2",
                contents: node => "test3",
              }
            },
            filename: 'annotations.st'
          }
        ],
        theme: "dark",
      }
    },

Would really appreciate if you could help with this? If you need any other blob of local nodes or other related configs from my end for looking into this, please let me know.

Thanks! :)

Add option to install Stork during CI builds.

Many users will deploy this using Github Actions, Netlify, or similar build providers. Installing Stork during CI builds by default (and allowing users to opt-out if needed) would save many users some headaches.

Support generating multiple search indexes.

Some users may want to generate multiple search indexes based on multiple queries or configurations, such as searching only on an individual page, search only through one subset of content, etc.

Feature Request: Add support for pathPrefix in the plugin

Building on #12 - When using pathPrefix, urls in the plugin config must be pre-process with gatsby's pathPrefix before sending to Stork. This will help achieve both seamless local develop testing as well as correct urls in search results for production builds.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.