Hi,
In some cases is useful to remove the slash at the beginning of the URL string or at the end of the URL string (as you said, the forward slash, also known as the trailing slash, hated in SEO optimizing). These two actions could be achieved using string.TrimPrefix and string.TrimSuffix. (See the doc for details: https://gohugo.io/functions/strings.trimprefix/ and https://gohugo.io/functions/strings.trimsuffix/)
As an example, here we have a shortcode for custom image handler in markdown files:
{{< image src="images/blog/some_image.jpg" alt="Some Fancy Image" >}}
And here, an usual user typo mistake, an slash at the beginning of the image URL.
{{< image src="/images/blog/some_image.jpg" alt="Some Fancy Image" >}}
For that reason could be useful to write the shortcode like this:
<div class="custom-aspect">
{{ if .IsNamedParams }}
<img src="{{ .Site.BaseURL | relURL }}{{ strings.TrimPrefix "/" (.Get "src") }}" alt="{{ .Get "alt" }}">
{{ else }}
<img src="{{ .Site.BaseURL | relURL }}{{ .Get 0 }}" alt="{{ .Get 1 }}">
{{ end }}
</div>
Now we have a shortcode with some handling for typo mistakes.