gatsby-plugin-prefix

0.1.1 • Public • Published

gatsby-plugin-prefix

Use prefix today, save time tomorrow

Table of Contents

Installation

npm install gatsby-plugin-prefix

Usage

  1. Register plugin

In gatsby-config.js:

module.exports = {
  plugins: [
    ...otherPlugins,
 
    {
      resolve: "gatsby-plugin-prefix",
      options: {
        tag: "tags",
        category: "categories",
        blog: "articles",
      },
    },
  ],
};

API

usePrefix

function() -> obj

This is a React hook that gives you access to the prefix objects that you declared when registering the plugin.

function MyComponent() {
  const { tag, category, blog } = usePrefix();
 
  console.log(tag); // --> tags
  console.log(category); // --> categories
  console.log(blog); // --> articles
 
  return <>{...}</>
}

Use Gatsby Node

This plugin creates a Prefix Gatsby node type. When working inside Gatsby lifecycle (createPages, sourceNodes, etc), you can run a Gatsby GraphQL to get the prefix data:

query {
  allPrefix {
    nodes {
      name
      value
    }
  }
}

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i gatsby-plugin-prefix

Weekly Downloads

2

Version

0.1.1

License

MIT

Unpacked Size

3.13 kB

Total Files

4

Last publish

Collaborators

  • alexluong