newbthenewbd / grav-plugin-tinymce-editor

TinyMCE Editor Integration Plugin for Grav
Other
60 stars 10 forks source link

Incorrect Image Path on Modular Page Component #18

Closed Tamriel closed 5 years ago

Tamriel commented 6 years ago

Images of blog items (partials/blog_item.html.twig) are not visible in the blog, but when viewing a single blog item: A blog, images not visible A blog item, images visible

This is because the generated html by this plugin is relative, e.g. <img src="my-blog-item/an-image.png" />. The html generated from markdown (without this plugin) has an absolute path to an image folder.

Steps to reproduce:

  1. Install Grav with Admin Plugin
  2. Install this plugin
  3. Create a site of type Blog
  4. Create a site of type Item below the Blog
  5. Add an image to the the blog item
newbthenewbd commented 6 years ago

Indeed, so far I have been trying to make the plugin use relative paths, in order to possibly minimize the amount of problems occurring when nested pages are renamed. AFAIK, the Markdown parser used by Grav generates every path dynamically, so it doesn't have the problem.

However, I think I've tested the trivial blog setup outlined in the steps to reproduce before, and it used to work.

newbthenewbd commented 6 years ago

Nevermind, looks like I got fooled by the Antimatter-induced header image. Issue confirmed, I guess, although I sadly cannot guarantee that it will be fixed soon, as I deem a full conversion to absolute paths insufficient, while figuring out a system to match Markdown might take time, and my free time is currently rather scarce.

Thanks for reporting!

Tamriel commented 6 years ago

Thanks for your explanations! I was able to solve it by adding the following below {{ page.content }} inside the file antimatter/templates/blog.html.twig:

<script>
  window.onload = function() {
    $('img').each(function() {
        var src = $(this).attr('src');
        if (src.charAt(0) != '/') {
          $(this).attr('src', '/blog/' + src); // prepend the path of the blog
        }
      });
  };
</script>
newbthenewbd commented 5 years ago

Fixed in v1.2.0, hopefully, although in a way that I still consider rather suboptimal - absolute paths are now used by default and patched as a page gets modified from within the admin panel, but when a page that has children is moved or renamed, its children unfortunately do not get patched, as I believe that this cannot currently be done without significant risk of data corruption.

Nevertheless, that would be a different issue, so for the sake of clarity closing this one - You're welcome to submit a new one if the new behavior proves problematic.