Migrate to Netlify Today

Netlify announces the next evolution of Gatsby Cloud. Learn more

ContactSign Up
Community Plugin
View plugin on GitHub

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.

© 2024 Gatsby, Inc.