Skip to content

fix: prevent gatsby file detection from breaking path field #1226

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

Merged
merged 1 commit into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions gatsby/onCreateNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

'use strict';

const path = require('path');

// Parse date information out of blog post filename.
const BLOG_POST_FILENAME_REGEX = /([0-9]+)\-([0-9]+)\-([0-9]+)\-(.+)\.md$/;

Expand All @@ -30,7 +32,7 @@ module.exports = exports.onCreateNode = ({node, actions, getNode}) => {
switch (node.internal.type) {
case 'MarkdownRemark':
const {permalink, redirect_from} = node.frontmatter;
const {relativePath} = getNode(node.parent);
const {relativePath, sourceInstanceName} = getNode(node.parent);

let slug = permalink;

Expand Down Expand Up @@ -71,10 +73,11 @@ module.exports = exports.onCreateNode = ({node, actions, getNode}) => {
});

// Used to generate a GitHub edit link.
// this presumes that the name in gastby-config.js refers to parent folder
createNodeField({
node,
name: 'path',
value: relativePath,
value: path.join(sourceInstanceName, relativePath),
});

// Used by createPages() above to register redirects.
Expand Down
2 changes: 1 addition & 1 deletion src/components/MarkdownPage/MarkdownPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const MarkdownPage = ({
<div css={{marginTop: 80}}>
<a
css={sharedStyles.articleLayout.editLink}
href={`https://github.com/reactjs/reactjs.org/tree/master/content/${
href={`https://github.com/reactjs/reactjs.org/tree/master/${
markdownRemark.fields.path
}`}>
Edit this page
Expand Down
4 changes: 1 addition & 3 deletions src/pages/docs/error-decoder.html.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ export const pageQuery = graphql`
markdownRemark(fields: {slug: {eq: $slug}}) {
html
fields {
path {
id
}
path
}
frontmatter {
title
Expand Down
4 changes: 1 addition & 3 deletions src/templates/blog.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ export const pageQuery = graphql`
}
fields {
date(formatString: "MMMM DD, YYYY")
path {
id
}
path
slug
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/templates/community.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ export const pageQuery = graphql`
prev
}
fields {
path {
id
}
path
slug
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/templates/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ export const pageQuery = graphql`
prev
}
fields {
path {
id
}
path
slug
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/templates/tutorial.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ export const pageQuery = graphql`
prev
}
fields {
path {
id
}
path
slug
}
}
Expand Down