-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Beta Bug: media_folder_relative also setting relative path when uploading images #2696
Comments
This is what that functionality is supposed to do, write a relative path to the image from the entry. However, I'm just realizing that it's calculating the relative path based on the entry location in source rather than the entry location on the published site 🤦♂ @s0 this is based on a quick glance, let me know if I'm missing something. If not we may need to revert this puppy. |
I haven't tested this, however from briefly reading the issue and your comment, it is supposed to calculate the relative path based on the source location, and not the published site. The idea is that you only use |
@s0 Yes, I got that and that's basically what the issue that led me to trying the beta in the first place. However, it's really easy to test that something must be off, because selecting an image in the admin area even breaks the preview of it: This is the resulting path that doesn't work in the admin view: However, this path would work in the admin: To me it looks like the relative path is technically set correctly, but gatsby will only look into static anyways as this is the designated media folder and thus the path will not lead to the right location. Let me know if this is still unclear, but for me even the plain netlify cms is not working with the intended implementation (broken preview image). |
If I'm following everyone correctly, it sounds like Netlify CMS needs to be aware of two types of relative paths at once when using this flag. One relative to production to enable display in the admin (sourced from the repo) and one relative to source so Gatsby can do its thing. To elaborate: Netlify CMS needs the original, unaltered relative path from the entry location of the published site (the one it typically outputs already) to source images from the repo correctly so that it can display images in the admin. In a Gatsby build, that would be If that's correct, it's imperative that anyone who uses this flag with Gatsby chooses the |
@s0 ah, right, that's it. As a matter of fact you're all correct lol. This is a complicated issue, which is why we hadn't taken it on just yet, really needs to be thought through on all sides. I'm certain that there are ways to pull this off though. Good breakdown @hu0p, we need both a relative source path and a relative production path. Could be relative to root for the production path as mentioned by @Jan17392. |
Ah yes, I forgot that previews don't work for this, and weren't fixed in my original PR, I mention it at the end of the description here: #2394. Rather than calculate the published path for an image, I feel it would make more sense to embed the image directly from the backend (e.g. GitHub) like is done with the gallery picker (IIRC), rather than try and resolve the published location for the image. This is slightly more robust, and allows for e.g. staging environments (master publishes to staging and is checked there before publishing a blog live), where the image may not yet be publicly accessible even if it's in git. |
I also have a somewhat alterior motive for doing it this way, which is to get preview images for #2397 working (where an image used in a post may not even be in the default branch at all yet). |
In any case, if calculating the (site-relative) production path is preferable for everyone else, it should be fairly easy to work that out from the existing configuration options. We can work that out fairly easy:
|
Perhaps this is an over-simplification/misunderstanding, but couldn't the
This can then be happily used in nuxt/gatsby/whatever as a psuedo-relative path, while the admin interface should still be okay finding assets since the paths aren't actually relative. EDIT: EDIT 2 (Edit Strikes Back): |
Sorry to jump in late into this discussion, but there might be another solution. |
Hi, do we have a proper fix for this? :) |
As a part of this #2958 image previews will always be taken directly from the repo and not the published site. Will work only for editorial workflow at the moment, but this #568 is next on our agenda. |
Closing as |
Describe the bug
I'm referring to a Gatsby issue Issue 4753, where you announced relative image paths in the beta. This works great for loading files from the static folder that already exist, but uploading a new file via the admin also saves them as relative paths to the .md file, making it impossible to find it later when loading (basically ignoring the media_folder setting).
To Reproduce
media_folder_relative: true media_folder: "static/uploads"
Expected behavior
Uploads should be saved as image: /uploads/logo.png, but instead they're saved as ../../../uploads/logo (number of directory changes depending on where the page lives).
Applicable Versions:
CMS configuration
`
backend:
name: gitlab
repo: ********
auth_type: implicit # Required for implicit grant
app_id: *********
api_root: ********
base_url: ********
auth_endpoint: oauth/authorize
media_folder_relative: true
media_folder: "static/uploads"
public_folder: "/uploads"
collections:
label: Navbar
folder: src/markdown/widgets/navbar
create: true
fields:
`
The text was updated successfully, but these errors were encountered: