Hugo

Forwards slashes are being replaced with \/ in my shortcodes

I’m faced with a weird problem.

I have a shortcode inlineScene called that creates in inline JS scene:

{{ $entry := .Get "entry" }}

<section id="scene"></section>

<script type="module">
  import init from 'main/{{ $entry }}';

  init( '#scene' );
</script>

Then I use it like this:

{{< inlineScene entry="path/scene.js" >}}

However, the output converts / to \/.

<section id="scene"></section>

<script type="module">
  import init from 'main/path\/scene.js';

  init( '#scene' );
</script>

What I have tried:

{{ $entry | safeJS }} 
{{ $entry | safeHTML }}
{{ $entry | safeURL }}
{{ $entry | jsonify }}
{{ $entry | urlize }}
{{ printf "%s" $entry }}

None of them fix this. I would have expected safeJS to be the correct choice here.

OK, I have found the solution.

This gives incorrect output:

import init from '{{ $entry }}';

--> '/path\/scene.js';

This gives correct output:

import init from {{ $entry }};

--> "/path/scene.js";

Since I have to append a directory to the start of $entry:

{{ $entry := (.Get "entry") }}

{{ $baseDir := "/static/examples/views/inline-scenes/" }}

{{ $path := printf "%s%s" $baseDir $entry }}

<script type="module">
  import init from 'main/{{ $path }}';
</script>