Skip to content
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

fix(gatsby-theme-blog): drop path.join to support windows #15370

Merged
merged 7 commits into from Jul 12, 2019

Conversation

wardpeet
Copy link
Contributor

@wardpeet wardpeet commented Jul 3, 2019

Description

creating urls with path.join isn working on osx & linux but sadly not on windows. This PR fixes that. I join by / and replace // or more into one /

before:
image

after:
image

@wardpeet wardpeet requested a review from a team as a code owner July 3, 2019 16:50
freiksenet
freiksenet previously approved these changes Jul 4, 2019
@sidharthachatterjee
Copy link
Contributor

Can't we use


const url = require('url');
url.resolve(basePath, dir, node.parent.name)

@wardpeet wardpeet added the status: blocked This issue/PR can't be solved at the moment and shouldn't be closed/merged label Jul 5, 2019
@wardpeet
Copy link
Contributor Author

wardpeet commented Jul 5, 2019

url.resolve has another use case. Check out https://nodejs.org/api/url.html#url_url_resolve_from_to it only works for 2 values

Currenly blocked on getting #15451 shipped

@talves
Copy link
Contributor

talves commented Jul 6, 2019

@wardpeet I tested the joinPath utility you propose on the slug in onCreateNode function (toPostPath) in my example and it will not solve the issue of an unexpected slug path. Instead of getting a slug with back slashes, which is happening now, that should be forward slashes, it returns the path with double back slashes now.

The issue is a node path.join returns a slug path with back slashes on windows that should be forward slashes in the slug for the browser. There needs to probably be a utility that converts paths to a valid relative slug path instead like below.

  const toSlugPath = node => {
    const { dir } = path.parse(node.relativePath)
    return join.path(basePath, dir, node.name).replace(/\\/g, '/')
  }

Of course, the toNotesPath function is a different issue that probably needs the proposed utility, but I did not look at that one.

@wardpeet
Copy link
Contributor Author

wardpeet commented Jul 8, 2019

It seems like joinPath isn't doing what I was told it did. It converts \ into \\ to safely store it to disk.

I have a new PR up #15510 that adds urlResolve

freiksenet
freiksenet previously approved these changes Jul 10, 2019
@wardpeet wardpeet removed the status: blocked This issue/PR can't be solved at the moment and shouldn't be closed/merged label Jul 12, 2019
Copy link
Contributor

@sidharthachatterjee sidharthachatterjee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @wardpeet 🥇

@sidharthachatterjee sidharthachatterjee added the bot: merge on green Gatsbot will merge these PRs automatically when all tests passes label Jul 12, 2019
@gatsbybot gatsbybot merged commit 1ee5b94 into gatsbyjs:master Jul 12, 2019
@wardpeet wardpeet deleted the fix/create-node-theme branch September 16, 2019 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: merge on green Gatsbot will merge these PRs automatically when all tests passes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants