Skip to content

Fixed the handling of custom image prefix #86

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
Apr 14, 2021

Conversation

javiereguiluz
Copy link
Collaborator

@javiereguiluz javiereguiluz commented Mar 23, 2021

I introduced some issues when refactoring this. The new proposed logic is:

  • If you provide a custom "image prefix", then the generated image URL is <your prefix> + / + <image relative path> (we don't change that URL to a relative one to avoid issues ... we use your provided prefix "as is")
  • If you don't provide this custom "image prefix", we consider that images are stored in <output dir>/_images/ and calculate image URLs as relative URLs.

if ('' === $this->buildConfig->getImagesPublicPrefix()) {
$newUrlPath = $node->getEnvironment()->relativeUrl('_images/'.$fileInfo->getFilename());
} else {
$newUrlPath = $this->buildConfig->getImagesPublicPrefix().'/'.$fileInfo->getFilename();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hii @javiereguiluz

we're copying the image to $this->buildConfig->getImagesDir().'/'.$fileInfo->getFilename() but we're linking to $this->buildConfig->getImagesPublicPrefix().'/'.$fileInfo->getFilename()

isn't there a problem if these two paths are uncorrelated?

in the test below, the img's src is /some/custom/prefix-for-images/symfony-logo.png but the image file path is ./_images/symfony-logo.png

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are right. However, this is intended.

The default behavior is unchanged (copy images in <contents/_images/ and link to them in that dir using a relative link). However, for advanced/custom setups, the images are copied to a separate dir (or even server/service like AWS). The missing piece that you mentioned is that in your own code using this Doc Builder you must take care of this and copy/move the images accordingly.

@weaverryan weaverryan merged commit 15631fc into symfony-tools:main Apr 14, 2021
@weaverryan
Copy link
Contributor

A test is included... so I'm happy with this if it gives us the end result we need :)

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

Successfully merging this pull request may close these issues.

3 participants