Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make the configured patterns queryable #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

trevorblades
Copy link

This change makes it possible to tell how the pattern option was configured for any GitRemote type. This is helpful for creating slugs for pages and knowing the basePath to pass to createFilePath. For example:

const globBase = require('glob-base');
const {createFilePath} = require('gatsby-source-filesystem');

exports.onCreateNode = ({node, getNode, actions}) => {
  const {type} = node.internal;
  if (type === 'MarkdownRemark' || type === 'Mdx') {
    const {gitRemote___NODE} = getNode(node.parent);
    const {patterns} = getNode(gitRemote___NODE);
    const {base} = globBase(patterns);
    const filePath = createFilePath({
      node,
      getNode,
      basePath: base
    });
  }
};

This change makes it possible to tell how the pattern option was configured for any `GitRemote` type. This is helpful for creating slugs for pages and knowing the `basePath` to pass to `createFilePath`. For example:

```js
const globBase = require('glob-base');
const {createFilePath} = require('gatsby-source-filesystem');

exports.onCreateNode = ({node, getNode, actions}) => {
  const {type} = node.internal;
  if (type === 'MarkdownRemark' || type === 'Mdx') {
    const {gitRemote___NODE} = getNode(node.parent);
    const {patterns} = getNode(gitRemote___NODE);
    const {base} = globBase(patterns);
    const filePath = createFilePath({
      node,
      getNode,
      basePath: base
    });
  }
};
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant