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

[gatsby-source-filesystem] add publicURL field #3669

Merged
merged 3 commits into from
Jan 26, 2018

Conversation

pieh
Copy link
Contributor

@pieh pieh commented Jan 23, 2018

This allow files to get copied to static directory and get their urls.

Closes #3538

@ghost ghost assigned pieh Jan 23, 2018
@ghost ghost added the review label Jan 23, 2018
@gatsbybot
Copy link
Collaborator

gatsbybot commented Jan 23, 2018

Deploy preview for gatsbygram ready!

Built with commit eca5cb0

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

Copy link
Contributor

@KyleAMathews KyleAMathews left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this! Looking good!

resolve: (file, fieldArgs, context) => {
const details = getNodeAndSavePathDependency(file.id, context.path)

const fileName = `${file.internal.contentDigest}${details.ext}`
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing the . between the two strings?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also let's include the original file name in the new pathname like here:

const imgSrc = `/${file.name}-${

Copy link
Contributor Author

Choose a reason for hiding this comment

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

details.ext already contains ., details.extension (or something like that) doesn't contain it.

Anyway this for this and rest of your definitly valid comments - this is basicly copied https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-transformer-sharp/src/extend-node-type.js#L105 minus image width, height part, plus path prefix which is propably missing in code I linked, actual image processing methods (sizes, resolutions) do honor path prefix.

I will fix those issues propably tomorrow.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh haha, well please fix transformer-sharp while you're at it :-)

if (!fs.existsSync(publicPath)) {
fs.copy(details.absolutePath, publicPath, err => {
if (err) {
console.error(`error copying file`, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Add the origin path and public path

const publicPath = path.join(
process.cwd(),
`public`,
`static/${fileName}`
Copy link
Contributor

Choose a reason for hiding this comment

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

make fileName another argument instead of joining them here.

…error in ImageSharp.original field, honor path prefix when returning public url, use image name as part of image created in static directory
@pieh
Copy link
Contributor Author

pieh commented Jan 24, 2018

Updated code. Also added gatsby-transformer-sharp changes here in seperate commit to not create more spam with seperate PR - if needed i can split it to keep it more contained.

@ghost ghost assigned KyleAMathews Jan 26, 2018
@KyleAMathews KyleAMathews merged commit 3f6f1e9 into gatsbyjs:master Jan 26, 2018
@ghost ghost removed the review label Jan 26, 2018
@KyleAMathews
Copy link
Contributor

Thanks! Now I can finally stop asking people in discord to implement this to solve their problem 😅

mwfrost pushed a commit to mwfrost/gatsby that referenced this pull request Apr 20, 2023
* add publicURL field to File node to allow copying assets to static directory and getting their paths

* [gatsby-transformer-sharp] add more details when reporting file copy error in ImageSharp.original field, honor path prefix when returning public url, use image name as part of image created in static directory

* Format
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.

3 participants