decaporg / decap-cms

A Git-based CMS for Static Site Generators
https://decapcms.org
MIT License
17.97k stars 3.05k forks source link

Unable to load images in the site if deployed in a sub-folder. #2332

Closed abhinavpreetu closed 4 years ago

abhinavpreetu commented 5 years ago

Describe the bug Failing to load images in the website as well as the preview section for sites in a sub-folder. For instance, www.example.com/netlify-cms-demo/.

To Reproduce

  1. Deploy a site at a sub-folder level.
  2. Try uploading an image from the Netlify-CMS. The image in the preview pane is broken as well as when I publish the site.

Expected behavior The images should load irrespective of the sub-folder deployment. The request for the images go to www.example.com/img/sample.png. But ideally it should go to www.example.com/netlify-cms-demo/img/sample.png. I am using Gatsby along with netlify-cms.

Applicable Versions:

CMS configuration media_folder: static/img public_folder: /img

Additional context I resolved the issue by prepending the sub-folder name to the public_folder property like

media_folder: static/img
public_folder: netlify-cms-demo/img

As I am using Gatsby, they handle the sub-folder issue using the property pathPrefix in the gatsby-config.js file. Similarly Hugo has baseUrl. If possible, can config.yml read the pathPrefix property in gatsby-config.jsor similar properties from other site generators and append it to the public_folder?

erquhart commented 5 years ago

Using public_folder isn't a workaround, it's the feature that provides support for your use case. This issue would be better presented as a feature request for automatically detecting site root from your SSG config. It's non-trivial as site generators vary, and a new extension interface would need to be defined and implemented to do it right, but we should at least start the conversation: #2347

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.