Coder Social home page Coder Social logo

gatsby-source-instance-name-for-remark's Introduction

Gatsby Plugin: Add SourceInstanceName to MarkdownRemark

MIT License CircleCI NPM

Add the options.name value from gatsby-source-filesystem to MarkdownRemark nodes for better filtering of different content types.

Install

# With Yarn
$ > yarn add -D gatsby-source-instance-name-for-remark

# With NPM
$ > npm install --save-dev gatsby-source-instance-name-for-remark

Configuration

// gatsby-config.js

module.exports = {
  siteMetadata: {
    title: "Gatsby Default Starter"
  },
  plugins: [
    {
      resolve: "gatsby-source-filesystem",
      options: {
        path: `${__dirname}/pages`,
        name: "pages"
      }
    },
    {
      resolve: "gatsby-source-filesystem",
      options: {
        path: `${__dirname}/products`,
        name: "products"
      }
    },
    "gatsby-transformer-remark",
    "gatsby-source-instance-name-for-remark"
  ]
};

License

Feel free to use the code, it's released using the MIT license.

Contribution

You are welcome to contribute to this project! ๐Ÿ˜˜

To make sure you have a pleasant experience, please read the code of conduct. It outlines core values and beliefs and will make working together a happier experience.

gatsby-source-instance-name-for-remark's People

Contributors

sbstjn avatar

Watchers

 avatar  avatar

gatsby-source-instance-name-for-remark's Issues

Cannot read properties of undefined (reading 'createNodeField'), gatsby-node.js:5:47

Got a bunch of these errors after installing and enabling gatsby-source-instance-name-for-remark when building on a "hello world" site with a folder added containing subfolders for a set of markdown files with images, with gatsby-source-filesystem and gatsby-transformer-remark the only other enabled plugins.

` ERROR #11321 API.NODE.EXECUTION

"gatsby-source-instance-name-for-remark" threw an error while running the onCreateNode lifecycle:

Cannot read properties of undefined (reading 'createNodeField')

3 | exports.onCreateNode = function (_a) {
4 | var node = _a.node, boundActionCreators = _a.boundActionCreators, getNode = _a.getNode;

5 | var createNodeField = boundActionCreators.createNodeField;
| ^
6 | if (node.internal.type === 'MarkdownRemark') {
7 | var parent_1 = getNode(node.parent);
8 | createNodeField({

File: node_modules/gatsby-source-instance-name-for-remark/gatsby-node.js:5:47

TypeError: Cannot read properties of undefined (reading 'createNodeField')

  • gatsby-node.js:5 Object.exports.onCreateNode
    [pickingl]/[gatsby-source-instance-name-for-remark]/gatsby-node.js:5:47

  • api-runner-node.js:487 runAPI
    [pickingl]/[gatsby]/src/utils/api-runner-node.js:487:37

`

My guess is it's the images, which aren't processed by transformer-remark, so perhaps don't have a "boundActionCreators"? Moving line 5 of gatsby-node.js below line 6, so createNodeField is only called if it's a markdown file, solves the problem for me.

Instance name in wrong property

Hi, the README file states the instance name would be inside options.name property, instead I found it inside fields.sourceInstanceName.

Could you please update the README?

Thank you for this plugin, it's very useful!

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.