Browse Source

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

Fixes #1088

This should fix the path issues that people intermittently run into.
Gatsby sees the relative path (and the parent node with an absolute
path), joins on the parent path and the relative path, and presumes it's
a file... which is normally good, but which here is not what we want
beacuse then we're getting a resolver of type file instead of type
string referring to the relative path of the document.

This seems to fix a (long standing?) bug where the "Edit this Page"
button is broken, as well. e.g. see [this page](https://reactjs.org/community/support.html) which _should_ have an Edit this Page button

I'd need to think more as to whether there's a cleaner fix here, but
this seems to work pretty well!
main
Dustin Schau 7 years ago
committed by Alex Krolick
parent
commit
7d12082d8b
  1. 7
      gatsby/onCreateNode.js
  2. 2
      src/components/MarkdownPage/MarkdownPage.js
  3. 4
      src/pages/docs/error-decoder.html.js
  4. 4
      src/templates/blog.js
  5. 4
      src/templates/community.js
  6. 4
      src/templates/docs.js
  7. 4
      src/templates/tutorial.js

7
gatsby/onCreateNode.js

@ -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$/;
@ -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;
@ -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.

2
src/components/MarkdownPage/MarkdownPage.js

@ -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

4
src/pages/docs/error-decoder.html.js

@ -107,9 +107,7 @@ export const pageQuery = graphql`
markdownRemark(fields: {slug: {eq: $slug}}) {
html
fields {
path {
id
}
path
}
frontmatter {
title

4
src/templates/blog.js

@ -58,9 +58,7 @@ export const pageQuery = graphql`
}
fields {
date(formatString: "MMMM DD, YYYY")
path {
id
}
path
slug
}
}

4
src/templates/community.js

@ -33,9 +33,7 @@ export const pageQuery = graphql`
prev
}
fields {
path {
id
}
path
slug
}
}

4
src/templates/docs.js

@ -38,9 +38,7 @@ export const pageQuery = graphql`
prev
}
fields {
path {
id
}
path
slug
}
}

4
src/templates/tutorial.js

@ -36,9 +36,7 @@ export const pageQuery = graphql`
prev
}
fields {
path {
id
}
path
slug
}
}

Loading…
Cancel
Save