How to use gatsby-source-filesystem - 10 common examples

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 jessestuart / gatsby-source-s3-image / src / __tests__ / source-nodes.spec.ts View on Github external
beforeEach(() => {
    sourceNodeArgs.store = configureMockStore()
    ListObjectsMock.mockReset()
    // Mock out Gatby's source-filesystem API.
    sourceFilesystem.createRemoteFileNode = jest
      .fn()
      .mockReturnValue(FileSystemNodeMock.build())
  })
github vibertthio / portfolio / gatsby-node.js View on Github external
exports.onCreateNode = ({ node, getNode, boundActionCreators }) => {
	const { createNodeField } = boundActionCreators;
	if (node.internal.type === 'MarkdownRemark') {
		// I put the index.js with index.md. Therefore, I have to give it specific path
		const slug = createFilePath({ node, getNode, basePath: 'pages' });
		// const slug = createFilePath({ node, getNode, basePath: 'pages' }).concat('index.md');
		// console.log(`slug for ${node.id} : ${slug}`);
		createNodeField({
			node,
			name: 'slug',
			value: slug,
		});
	}
};
github dice-group / dice-website / scripts / gatsby-node.js View on Github external
exports.onCreateNode = ({ node, actions, getNode }) => {
  const { createNodeField } = actions;
  // We only want to operate on `Mdx` nodes. If we had content from a
  // remote CMS we could also check to see if the parent node was a
  // `File` node here
  if (node.internal.type === 'Mdx') {
    // generate path from frontmatter or from node path
    const basePath = createFilePath({ node, getNode });
    const nodePath =
      node.internal.frontmatter && node.internal.frontmatter.path
        ? node.internal.frontmatter.path
        : basePath;
    createNodeField({
      name: 'path',
      node,
      value: nodePath,
    });

    // generate article type from frontmatter or from node path
    const baseType = basePath.split('/')[1] || 'page';
    const nodeType =
      node.internal.frontmatter && node.internal.frontmatter.type
        ? node.internal.frontmatter.type
        : baseType;
github Financial-Times / x-dash / tools / x-docs / plugins / gatsby-plugin-packages / gatsby-node.js View on Github external
const readmePath = path.resolve(packageFullPath, 'readme.md');
		const docsPath = path.resolve(packageFullPath, 'docs');
		const basePath = packagePath.split(path.sep).shift();

		// load the package manifest
		const manifest = require(manifestPath);

		// check if the source files exist
		const [ hasReadme, hasDocs ] = await Promise.all([
			fs.pathExists(readmePath),
			fs.pathExists(docsPath)
		]);

		// pull all of the files into Gatsby
		await Promise.all([
			filesystem.sourceNodes(props, {
				name: `package-${packagePath}`,
				path: manifestPath
			}),
			hasReadme && filesystem.sourceNodes(props, {
				name: `package-${packagePath}`,
				path: readmePath
			}),
			hasDocs && filesystem.sourceNodes(props, {
				name: `package-${packagePath}`,
				path: docsPath
			})
		]);

		// HACK: attempt to pull in any stories from workbench for this package
		const { stories } = components.find((component) => {
			return component.package.name === manifest.name;
github molebox / gatsby-theme-west-egg / packages / gatsby-theme-west-egg-mdx-blog / gatsby-node.js View on Github external
exports.onCreateNode = ({ node, actions, getNode }) => {
  const { createNodeField } = actions;
  // We only want to operate on `Mdx` nodes. If we had content from a
  // remote CMS we could also check to see if the parent node was a
  // `File` node here
  if (node.internal.type === "Mdx") {
    const value = createFilePath({ node, getNode });
    createNodeField({
      // Name of the field you are adding
      name: "slug",
      // Individual MDX node
      node,
      // Generated value based on filepath with "blog" prefix
      value: `/blog${value}`
    });
  }
};
github Takumon / blog / plugins / gatsby-remark-and-qiita / gatsby-node.js View on Github external
if (node.internal.type !== `MarkdownRemark` && node.internal.type !== `QiitaPost`) {
    return
  }


  const [
    slug,
    title,
    date,
    excerpt,
    tags,
    thumbnail,
  ] =
    node.internal.type === `MarkdownRemark`
      ? [
        node.frontmatter.slug || createFilePath({ node, getNode }), // 記事でURL指定があればそちらを優先する
        node.frontmatter.title,
        node.frontmatter.date,
        _excerptMarkdown(node.rawMarkdownBody, 120),
        node.frontmatter.tags,
        node.frontmatter.thumbnail
      ]
      :[
        `/${node.id}/`,
        node.title,
        node.created_at,
        _excerptHtml(node.rendered_body, 120),
        [...(node.tags.map(tag => tag.name) || []), 'Qiita'], // Qiitaタグを追加
        undefined,
      ]
github ajmalafif / netsby / gatsby-node.js View on Github external
exports.onCreateNode = ({ node, actions, getNode }) => {
  const { createNodeField } = actions
  fmImagesToRelative(node) // convert image paths for gatsby images

  if (node.internal.type === `MarkdownRemark`) {
    const value = createFilePath({ node, getNode })
    createNodeField({
      name: `slug`,
      node,
      value,
    })
  }
}
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 4 months ago

Package Health Score

94 / 100
Full package analysis