Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "gatsby-source-filesystem in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'gatsby-source-filesystem' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

beforeEach(() => {
    sourceNodeArgs.store = configureMockStore()
    ListObjectsMock.mockReset()
    // Mock out Gatby's source-filesystem API.
    sourceFilesystem.createRemoteFileNode = jest
      .fn()
      .mockReturnValue(FileSystemNodeMock.build())
  })
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,
		});
	}
};
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;
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;
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}`
    });
  }
};
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,
      ]
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,
    })
  }
}
// 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)
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))
  }
}
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))
  }
}

Is your System Free of Underlying Vulnerabilities?
Find Out Now