kirby3-static-site-generator: Plugin generates wrong URL paths and HTML tags when baseUrl is set

I am using this plugin via a separate PHP file like this:

<?php
  require('./index.php');
  $kirby = kirby();
  $staticSiteGenerator = new D4L\StaticSiteGenerator($kirby);
  $list = $staticSiteGenerator->generate($outputFolder = './foobar', $baseUrl = '/foobar/', $preserve = []);
  echo json_encode($list, JSON_PRETTY_PRINT);

All pages are exported correctly, however all paths in the HTML files have the word “foobar” in them, e.g.

<meta property="og:image" content="/foobar/assets/foobar/img/foobar/opengraph.png">

<img class="img-fluid" src="/foobar/media/foobar/pages/foobar/hosts/foobar/daniel-burka/foobar/84a8cc761f-1626254128/foobar/1516277198735-768x768.jpg" alt="Some Alt Description">

Furthermore a few HTML tags have been changed, e.g.

<title>Page Title</foobar/title>

</foobar/div>

It seems that this str_replace (https://github.com/d4l-data4life/kirby3-static-site-generator/blob/master/class.php#L96) might be the culprit as all / seem to have been replaced.

Expected Behavior

Paths should not be changed, except the base_url parameter HTML Tags should stay as they are

Current Behavior

The plugin currently generates broken HTML and wrong paths.

Steps to Reproduce

  • Execute the PHP script above

Context

  • Kirby 3.5.7.1
  • Kirby Builder 2.0.16
  • Meta Tags 2.1.0
  • Static Site Generator 1.1.1
  • PHP 7.4.21

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (9 by maintainers)

Most upvoted comments

Thanks @jonathan-reisdorf, I’ve just tested this and can confirm it works as expected.

@dgsiegel thank you for bringing this up, I have a fix ready which I’ll commit in a minute

Hi @dgsiegel, thank you for reporting this! I was not aware that it’s an option to leave the base url empty. In this case I’ll have to temporarily set it in the plugin to have a placeholder/marker in the html the plugin can then replace.

I’ll create a PR for the fix later today.