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.

Note that this plugin runs after the build, not after the bootstrap, so the index won’t be generated when running gatsby develop. To test locally, use gatsby build && gatsby serve.

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",
          query: `
              {
                site {
                  siteMetadata { siteUrl }
                }
                allMdx(
                  limit: 1000
                ) {
                  edges {
                    node {
                      rawBody
                      fields { slug }
                      frontmatter { title }
                    }
                  }
                }
              }
            `,
            serialize: ({ allMdx }) => yourSerializationFunction(allMdx),
            filename: "indexFile.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="indexFile.st" placeholder="🔍" />
  );
}

Configuration Options

query

This is the query that will be run to pull in any pages you want to be indexed. The result of this query will be passed to the serialize function.

serialize

This function serializes your query into a proper list of files. Note that this list of files will be used to create the toml config file that generates your Stork index, so the list of objects must conform to valid file objects.

filename

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

outputDir

The directory where the index will be stored. By default, it is stored in the public directory of your project. We do not recommend changing this unless you will be storing the index file somewhere else (such as your own external CDN).

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 until it has some users, 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.