How to use the gatsby-source-filesystem.loadNodeContents function in gatsby-source-filesystem

To help you get started, we’ve selected a few gatsby-source-filesystem examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gatsbyjs / gatsby / packages / gatsby-parser-remark / src / gatsby-node.js View on Github external
// https://github.com/github/markup/blob/cf74e842dfd082d8001417c1bb94edd2ae06d61b/lib/github/markup/markdown.rb#L28
  const extensions = [
    "md",
    "rmd",
    "mkd",
    "mkdn",
    "mdwn",
    "mdown",
    "litcoffee",
    "markdown",
  ]
  if (!_.includes(extensions, node.extension)) {
    return
  }

  const content = await loadNodeContents(node)
  const data = grayMatter(content)
  const markdownNode = {
    _sourceNodeId: node.id,
    parent: node.id,
    type: `MarkdownRemark`,
    id: `${node.id} >> MarkdownRemark`,
    children: [],
    src: data.content,
  }
  markdownNode.frontmatter = {
    _sourceNodeId: node.id,
    ...data.data,
  }

  node.children = node.children.concat([markdownNode.id])
  updateNode(node)
github gatsbyjs / gatsby / packages / gatsby-parser-json / src / gatsby-node.js View on Github external
async function onNodeCreate({ node, actionCreators }) {
  const { createNode, updateNode } = actionCreators
  if (node.extension === `json`) {
    const content = await loadNodeContents(node)
    // TODO validate that the JSON object has an id field?
    // Or just add an id if one isn't set?
    const JSONArray = JSON.parse(content).map(obj => ({
      ...obj,
      _sourceNodeId: node.id,
      parent: node.id,
      type: _.capitalize(node.name),
      children: [],
    }))

    node.children = node.children.concat(JSONArray.map(n => n.id))
    updateNode(node)
    _.each(JSONArray, j => createNode(j))
  }
}
github gatsbyjs / gatsby / packages / gatsby-parser-yaml / src / gatsby-node.js View on Github external
async function onNodeCreate({ node, actionCreators }) {
  const { createNode, updateNode } = actionCreators
  if (node.extension === `yaml` || node.extension === `yml`) {
    const content = await loadNodeContents(node)
    // TODO validate that yaml object has an id field?
    // Or just add an id if one isn't set?
    const yamlArray = jsYaml.load(content).map(obj => ({
      ...obj,
      parent: node.id,
      _sourceNodeId: node.id,
      type: _.capitalize(node.name),
      children: [],
    }))

    node.children = node.children.concat(yamlArray)
    updateNode(node)
    _.each(yamlArray, y => createNode(y))
  }
}

gatsby-source-filesystem

Gatsby source plugin for building websites from local data. Markdown, JSON, images, YAML, CSV, and dozens of other data types supported.

MIT
Latest version published 2 months ago

Package Health Score

98 / 100
Full package analysis