d4l-data4life / kirby3-static-site-generator

Static site generator plugin for Kirby 3+. With this plugin you can create a directory with assets, media and static html files generated from your pages. The result is an even faster site with less potential vulnerabilities.
MIT License
138 stars 7 forks source link

Wrong baseUrl for some elements #90

Closed dimejo closed 6 months ago

dimejo commented 9 months ago

I have build a small project that is supposed to be a boilerplate for future static sites with Kirby. The project only consists of Kirby 4, the Starterkit and kirby3-static-site-generator. The site is automatically build by running a build.php script via Github Actions and then deployed to Github Pages. Everything is working well but I noticed that some images are not loaded because 'https://d4l-ssg-base-url' is used as $baseUrl instead of '/kirby-tailwind-static'.

Screenshot 2024-02-14 174542

URLs having this issue: https://dimejo.github.io/kirby-tailwind-static/about/ https://dimejo.github.io/kirby-tailwind-static/notes/exploring-the-universe/

The corresponding code seems to be generated by this snippet, but as I'm completely new to Kirby I have no idea what is going on.

jonathan-reisdorf commented 9 months ago

Hi, thank you for reporting the issue. Unfortunately I'm severely lacking the time at the moment but I will look into this in a couple of weeks. Thank you for linking the repo for reproducing the issue, that will help a lot with debugging.

jonathan-reisdorf commented 6 months ago

Hi, sorry for the late response. The issue here lies in https://github.com/dimejo/kirby-tailwind-static/blob/main/site/snippets/image.php#L11 which you copied from the new starterkit. The snippet escapes the image url which then breaks the part of the site generator which replaces the temporary full/absolute base url (which is needed for kirby) with the one you've set up.

You can solve this on your side by not using esc in conjunction with src or href. In your concrete example, that means replacing https://github.com/dimejo/kirby-tailwind-static/blob/main/site/snippets/image.php#L11 with

    src="<?= $src ?>"
dimejo commented 6 months ago

@jonathan-reisdorf: Thanks for the pointer. Using the esc() helper works, but not in combination with 'attr' it seems. What confused me was the fact that it works on a live site, but not with this plugin. Hence I suspected a bug in this plugin.