Skip to content

Gatsby

There is a plugin available to simplify the integration of Honegumi with Gatsby.

yarn add brendanmckenzie/gatsby-source-honegumi.git
# or
npm install --save brendanmckenzie/gatsby-source-honegumi.git

This library is still WIP and as such has not been released to npmjs.com yet.

Gatsby configuration

Once installed, add the following configuration to your gatsby-config.js plugin configuration.

{
  resolve: "gatsby-source-honegumi",
  options: {
    project: process.env.HON_PROJECT,
    token: process.env.HON_TOKEN,
    taxonomy: {
      skip: 1,
      resolveComponent: (input) =>
        require.resolve(`./src/templates/${input.model}.tsx`),
    }
  },
}

Required options

The required options for this plugin are

  • project this is the project identifier you can find on your projects dashboard
  • token this is your API token. See the authentication article for details on how to obtain these values

Additional options

These options are only useful if you are using the Structure feature of Honegumi, they will not have any effect if you are not.

  • taxonomy tells the plugin to read the taxonomy information and call the createPages Gatsby method for each entry it comes across
  • taxonomy.skip tells the plugins how many levels of taxonomy to skip. If your website's home node is located at /example/website/home then this value would be 3
  • taxonomy.resolveComponent maps each node in the taxonomy to a page template
  • taxonomy.filter allows you to specify which nodes to call createPages for

Enabling this feature by specifying the above parameters causes the plugin to call createPages for each entry in the taxonomy.

The plugin will pass an object with the following structure to the context of the page.

type TaxonomyNode = {
  entryId: string; // the ID of the entry, this can be used to query additional information
  model: string; // the alias of the entry's model
  taxonomyPath: string; // the relative path of the entry in the taxonomy tree
};

The source code for this plugin is available on Github.