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

Consistently pass the pathPrefix with linked files #3338

Conversation

seryl
Copy link
Contributor

@seryl seryl commented Dec 25, 2017

Fixes copied gifs and svgs missing the pathPrefix for production builds.

Refs #2440

@gatsbybot
Copy link
Collaborator

gatsbybot commented Dec 25, 2017

Deploy preview for gatsbygram ready!

Built with commit d94e0c271596de80a58788810cc5c07b04a5b02c

https://deploy-preview-3338--gatsbygram.netlify.com

@seryl
Copy link
Contributor Author

seryl commented Dec 25, 2017

I could also make it so that copy-linked-files puts items in the /static directory - should we do that?

Let me know what you think.

pluginOptions = {}
) => {
const defaults = {
ignoreFileExtensions: [`png`, `jpg`, `jpeg`, `bmp`, `tiff`],
pathPrefix,
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't necessary since pathPrefix is a global option and plugins shouldn't have option for overriding it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the delay, I had to do some investigation into what other packages were doing.

When I remove this it fails, what should I be doing here instead? It's not clear how I should be using pathPrefix for options.

I was using remark-images for reference originally. Is this incorrect as well?

Should I be using globals like gatsby-link instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

What I'm saying is just pass pathPrefix to newLinkUrl instead of making pathPrefix an option.

process.cwd(),
`public`,
validDestinationDir,
`/undefined-undefined.gif`
Copy link
Contributor

Choose a reason for hiding this comment

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

why undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why undefined

I believe the reason it's undefined is because when this is run, there are no actual images for it to the filenames from.

undefined-undefined.gif represents FILENAME-DIGEST.gif

I'm not sure where/when the filename and digest are created but at the time of the test, these values don't exist in the hash. I'm still looking into this.

It originates here but I'm not sure when those values actually get set (I'm still looking around).

For the added test itself

All we're doing here is taking the markdownAST children.

This is just validating that the additional pathPrefix is joined.

The existing test without the prefix is here: #L239-L258

I'm just adding an additional test to validate that the prefix exists when it's set.

const newLinkURL = (linkNode, destinationDir, pathPrefix) => {
const linkPaths = [`/`, pathPrefix, destinationDir, newFileName(linkNode)]
.filter(function(lpath) {
if (lpath) return true
Copy link
Contributor

Choose a reason for hiding this comment

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

What's this for?

Copy link
Contributor Author

@seryl seryl Jan 10, 2018

Choose a reason for hiding this comment

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

If you build with yarn develop; the urls are correct.

When building for production, the current code does not append the pathPrefix.

This just allows you to optionally specify a pathPrefix; it filters it out if pathPrefix happens to be empty or null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This produces the same result as joining paths like gatsby-link.

However, gatsby link has to create a string, run a regex and return a new string.

The logic I have just creates the string ignoring pathPrefix if it isn't set.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, so you're filtering out the sometimes empty pathPrefix 👍

@@ -76,7 +80,7 @@ module.exports = (
// Prevent uneeded copying
if (linkPath === newFilePath) return

const linkURL = newLinkURL(linkNode, options.destinationDir)
const linkURL = newLinkURL(linkNode, options.destinationDir, options.pathPrefix)
Copy link
Contributor

Choose a reason for hiding this comment

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

change options.pathPrefix to pathPrefix

@KyleAMathews
Copy link
Contributor

Hey @seryl would you like to finish this out?

@seryl
Copy link
Contributor Author

seryl commented Apr 4, 2018 via email

@KyleAMathews
Copy link
Contributor

Thanks!

@seryl seryl closed this Apr 4, 2018
@seryl seryl force-pushed the add-pathPrefix-support-remark-copy-linked-files branch from d94e0c2 to 2e49112 Compare April 4, 2018 16:54
@gatsbybot
Copy link
Collaborator

Deploy preview for using-drupal ready!

Built with commit 2e49112

https://deploy-preview-3338--using-drupal.netlify.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants