Slash delimiter problem between test and production

I have a problem making a partial work, because of differences between the value of .Site.BaseURL for my test and my production instance.

In production, the root of my site is https://developers.<blah>.com.

In test, the root is http://preview.<foo>.<bar>.com/<snafu>/<branchname> (Our test deployment system can make a separate instance of the site for each git branch I put into GitHub).

One of my partials uses this markup: {{ .Site.BaseURL }/}<filename>_reference.html to link to a static HTML file.

When the deployment system builds production, .Site.BaseURL turns into https://developers.<blah>.com, so the markup is rendered as https://developers.<blah>.com/<filename>_reference.html, which works.

When the deployment system builds to test, .Site.BaseURL turns into http://preview.<foo>.<bar>.com/<snafu>/<branchname>//<filename>_reference.html (note the two slashes between
<branchname> and <filename>, which doesn’t work.

Am I doing something wrong? Is there a way to have one version of the partial that works for test and for production?

A few ways to do this that I know of

(1) Use strings.TrimSuffix to trim the trailing slash if it exists (the url remains unchanged if not) then add the slash back in

(2) Use absURL on your static file, which handles base url trailing slash automatically

1 Like

Not sure what you mean by “Use absURL on your static file”. Do you mean that the partial should use

{{ .Site.absURL }}<filename>_reference.html?

An example

{{ "filename_reference.html" | absURL }}
1 Like

Ah. OK!

Tested, and it works perfectly. Thank you!:heart_eyes:

1 Like