Example #1
0
exports.onCreateNode = ({ node, boundActionCreators, getNode }) => {
  const { createNodeField } = boundActionCreators;
  if (node.internal.type === 'MarkdownRemark') {
    const filename = createFilePath({ node, getNode, basePath: 'pages' });

    // get the date and title from the file name
    const [, date, title] = filename.match(/^\/([\d]{4}-[\d]{2}-[\d]{2})-(.+)\/$/);
    // create a new slug like jekyll used to
    const slug = `/${date.split('-').join('/')}/${title}/`;

    createNodeField({
      node,
      name: 'slug',
      value: slug,
    });

    // save the date for later use
    createNodeField({
      node,
      name: 'date',
      value: date,
    });

    // save slugTitle
    createNodeField({
      node,
      name: 'slugTitle',
      value: title,
    });
  }
};
exports.onCreateNode = ({
  node,
  getNode,
  loadNodeContent,
  boundActionCreators,
}) => {
  const { createNodeField } = boundActionCreators

  const { frontmatter } = node
  if (frontmatter) {
    const { image } = frontmatter
    if (image) {
      if (image.indexOf('/img') === 0) {
        frontmatter.image = path.relative(
          path.dirname(node.fileAbsolutePath),
          path.join(__dirname, '/static/', image)
        )
      }
    }
  }

  if (node.internal.type === `MarkdownRemark`) {
    const value = createFilePath({ node, getNode })
    createNodeField({
      name: `slug`,
      node,
      value,
    })
  }
}
Example #3
0
exports.onCreateNode = function onCreateNode({ node, actions, getNode }) {
  const { createNodeField } = actions;
  if (node.internal.type === 'ChallengeNode') {
    const { tests = [], block, title, superBlock } = node;
    const slug = `/learn/${dasherize(superBlock)}/${dasherize(
      block
    )}/${dasherize(title)}`;
    createNodeField({ node, name: 'slug', value: slug });
    createNodeField({ node, name: 'blockName', value: blockNameify(block) });
    createNodeField({ node, name: 'tests', value: tests });
  }

  if (node.internal.type === 'MarkdownRemark') {
    let slug = createFilePath({ node, getNode });
    if (!slug.includes('LICENSE')) {
      createNodeField({ node, name: 'slug', value: slug });
    }
  }
  if (node.internal.type === 'NewsArticleNode') {
    const {
      author: { username },
      slugPart,
      shortId
    } = node;
    const slug = createArticleSlug({ username, shortId, slugPart });
    createNodeField({ node, name: 'slug', value: slug });
  }
};
Example #4
0
exports.onCreateNode = ({ node, actions, getNode }) => {
  const { createNodeField } = actions;

  if (node.internal.type === "File") {
    const parsedFilePath = path.parse(node.absolutePath);
    const slug = `/${parsedFilePath.dir.split("---")[1]}/`;
    createNodeField({ node, name: "slug", value: slug });
  } else if (node.internal.type === "MarkdownRemark") {
    const value = createFilePath({ node, getNode });
    createNodeField({
      node,
      name: "slug",
      value: value.replace(/pages\//, "").replace(/\d\d\d\d-\d\d-\d\d-/, ""),
    });

    if (node.frontmatter.tags) {
      const tagSlugs = node.frontmatter.tags.map(
        (tag) => `/tags/${_.kebabCase(tag)}/`,
      );
      createNodeField({ node, name: "tagSlugs", value: tagSlugs });
    }

    if (typeof node.frontmatter.category !== "undefined") {
      const categorySlug = `/categories/${_.kebabCase(
        node.frontmatter.category,
      )}/`;
      createNodeField({ node, name: "categorySlug", value: categorySlug });
    }
  }
};
Example #5
0
exports.onCreateNode = function onCreateNode({ node, actions, getNode }) {
  const { createNodeField } = actions;
  if (node.internal.type === 'ChallengeNode') {
    const { tests = [], block, title, superBlock } = node;
    const slug = `/learn/${dasherize(superBlock)}/${dasherize(
      block
    )}/${dasherize(title)}`;
    createNodeField({ node, name: 'slug', value: slug });
    createNodeField({ node, name: 'blockName', value: blockNameify(block) });
    createNodeField({ node, name: 'tests', value: tests });
  }

  if (node.internal.type === 'MarkdownRemark') {
    const slug = createFilePath({ node, getNode });
    if (!slug.includes('LICENSE')) {
      const {
        fileAbsolutePath,
        frontmatter: { component = '' }
      } = node;
      createNodeField({ node, name: 'slug', value: slug });
      createNodeField({ node, name: 'component', value: component });
      createNodeField({
        node,
        name: 'githubPath',
        value: getGithubPath(fileAbsolutePath)
      });
    }
  }
};
Example #6
0
module.exports = function addSlugToNode (createNodeField, getNode, node) {
  const slug = createFilePath({ getNode, node })
  createNodeField({
    name: 'slug',
    node,
    value: slug
  })
  return slug
}
Example #7
0
exports.onCreateNode = ({node, getNode, actions}) => {
  const {createNodeField} = actions

  if (node.internal.type === 'MarkdownRemark') {
    const slug = createFilePath({node, getNode, basePath: 'pages'})
    createNodeField({
      node,
      name: 'slug',
      value: slug
    })
  } else if (node.internal.type === 'WorkJson') {
    const slug = createFilePath({node, getNode, basePath: 'data/work'})
    createNodeField({
      node,
      name: 'slug',
      value: slug
    })
  }
}
Example #8
0
exports.onCreateNode = ({node, getNode, actions}) => {
  if (node.internal.type === 'MarkdownRemark') {
    const route = createFilePath({node, getNode});
    const group = route.split('/')[1];
    const isReadme = /\/readme.md/i.test(node.fileAbsolutePath);

    actions.createNodeField({node, name: 'route', value: route});
    actions.createNodeField({node, name: 'group', value: group});
    actions.createNodeField({node, name: 'isReadme', value: isReadme});
  }
};
Example #9
0
exports.onCreateNode = ({ node, getNode, actions }) => {
  const { createNodeField } = actions;
  if (node.internal.type === 'MarkdownRemark') {
    const slug = createFilePath({ node, getNode, basePath: 'pages' });
    createNodeField({
      node,
      name: 'slug',
      value: slug
    });
  }
};
exports.onCreateNode = ({ node, boundActionCreators, getNode }) => {
  const { createNodeField } = boundActionCreators;

  if (node.internal.type === `MarkdownRemark`) {
    const value = createFilePath({ node, getNode });
    createNodeField({
      name: `slug`,
      node,
      value
    });
  }
};
Example #11
0
exports.onCreateNode = ({ node, actions, getNode }) => {
  const { createNodeField } = actions

  if (node.internal.type === `MarkdownRemark`) {
    const value = createFilePath({ node, getNode })
    createNodeField({
      name: `slug`,
      node,
      value,
    })
  }
}
Example #12
0
exports.onCreateNode = ({ node, boundActionCreators, getNode }) => {
  const { createNodeField } = boundActionCreators

  if (node.internal.type === 'MarkdownRemark') {
    const value = createFilePath({ node, getNode })
    createNodeField({
      name: 'slug',
      node,
      value,
    })
  }
}
Example #13
0
exports.onCreateNode = ({ node, actions, getNode }) => {
  const { createNodeField } = actions

  if (node.internal.type === 'Mdx') {
    const value = node.frontmatter.path || createFilePath({ node, getNode })
    createNodeField({
      name: 'slug',
      node,
      value,
    })
  }
}
exports.onCreateNode = ({ node, getNode, getNodes, boundActionCreators }) => {
  const { createNodeField } = boundActionCreators

  if (node.internal.type === 'MarkdownRemark') {
    const slug = createFilePath({ node, getNode, basePath: 'pages' })

    createNodeField({
      node,
      name: 'slug',
      value: slug,
    })
  }
};
Example #15
0
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,
    });
  }
};
Example #16
0
exports.onCreateNode = ({ node, getNode, actions }) => {
  if (node.internal.type === 'MarkdownRemark') {
    // const fileNode = getNode(node.parent)
    const slug = createFilePath({ node, getNode, basePath: `posts` })

    const { createNodeField } = actions

    // add slug
    createNodeField({
      node,
      name: 'slug',
      value: '/blog' + slug
    })
  }
}
Example #17
0
export const onCreateNode = ({
	node,
	getNode,
	actions: { createNodeField },
}) => {
	if (node.internal.type === 'MarkdownRemark') {
		const slug = createFilePath({ node, getNode });

		// Typography
		node.internal.content = typo(node.internal.content);

		createNodeField({
			node,
			name: 'slug',
			value: slug,
		});
	}
};
Example #18
0
function processMarkdownPage({ node, getNode, actions }) {
  const { createNodeField } = actions
  const slug = createFilePath({ node, getNode, basePath: 'posts' })
  let title = node.frontmatter.title
  let nameArr = slug.replace(/\//g, '').split('-')
  const [year, month, day, ...titleRest] = nameArr
  if (title === '') {
    title = nameArr.join(' ').replace('.md', '')
  }
  const newSlug = `/${year}/${month}/${day}/${titleRest.join('-')}/`
  const date = new Date([year, month, day].join('-'))
  // console.log('creating node..: ', { slug, newSlug })

  createNodeField({
    node,
    name: 'slug',
    value: newSlug,
  })
  createNodeField({
    node,
    name: 'title',
    value: title,
  })
  createNodeField({
    node,
    name: 'year',
    value: year,
  })
  createNodeField({
    node,
    name: 'date',
    value: date.toLocaleDateString('en-US', {
      year: 'numeric',
      month: 'long',
      day: 'numeric',
    }),
  })
}
Example #19
0
module.exports = ({ node, getNode, actions }) => {
  const { createNodeField } = actions

  if (node.internal.type === `MarkdownRemark`) {
    const {
      permalink,
      redirect_from,
      category,
      layout,
      lead,
      subtitle,
      link,
      header_image,
      youtube_embed_id,
      date
    } = node.frontmatter
    const relativePath = createFilePath({ node, getNode, basePath: 'pages' })

    let slug = permalink

    if (!slug && relativePath.includes('posts')) {
      // Generate final path + graphql fields for blog posts
      const match = BLOG_POST_SLUG_REGEX.exec(relativePath)
      if (match) {
        const year = match[1]
        const month = match[2]
        const day = match[3]
        const filename = match[4]

        slug = `/posts/${year}/${month}/${day}/${slugify(filename)}/`

        const pubDate = date
          ? new Date(date)
          : new Date(
              Number.parseInt(year, 10),
              Number.parseInt(month, 10) - 1,
              Number.parseInt(day, 10)
            )

        // Blog posts are sorted by date and display the date in their header.
        createNodeField({
          node,
          name: 'date',
          value: pubDate.toJSON()
        })
      }
    }

    if (!slug && relativePath.includes('projects')) {
      const { tags, year, description, project_url, jumpToProject } = node.frontmatter

      createNodeField({
        node,
        name: 'tags',
        value: tags ? JSON.stringify(tags) : ''
      })

      createNodeField({
        node,
        name: 'year',
        value: year || ''
      })

      createNodeField({
        node,
        name: 'description',
        value: description || ''
      })

      createNodeField({
        node,
        name: 'jumpToProject',
        value: jumpToProject ? JSON.stringify(jumpToProject) : JSON.stringify(false)
      })

      createNodeField({
        node,
        name: 'project_url',
        value: project_url || ''
      })
    }

    if (!slug) {
      slug = relativePath
    }

    // Used to generate URL to view this content.
    createNodeField({
      node,
      name: `slug`,
      value: slug
    })

    // Used to determine a page layout.
    createNodeField({
      node,
      name: 'layout',
      value: layout || ''
    })

    // Used to determine the post category.
    createNodeField({
      node,
      name: 'category',
      value: category || ''
    })

    createNodeField({
      node,
      name: 'link',
      value: link || ''
    })

    // Used to add a lead text.
    createNodeField({
      node,
      name: 'lead',
      value: lead || subtitle || ''
    })

    // Generate an absolute path for a page's header image.
    createNodeField({
      node,
      name: 'headerImage',
      value: header_image || ''
    })

    // Include YT embed id if available
    createNodeField({
      node,
      name: 'youtube_embed_id',
      value: youtube_embed_id || ''
    })

    // Used by createPages() to register redirects.
    createNodeField({
      node,
      name: 'redirect',
      value: redirect_from ? JSON.stringify(redirect_from) : ''
    })
  }
}