Best way to reference an image in `/static` directory when baseURL could contain a sub-directory?

So if baseURL = xxx/gg, using the following code in markdown would not work

![alt](/image/test.jpg)

However, we would not want to hardcode the gg into the markdown like this:

![alt](/gg/image/test.jpg)

I know we could set canonifyURLs = true, but doing so would cause some unwanted side effects:

Also, I heard that canonifyURLs is marked for removal, so I am not sure if there is a better way to reference images in the markdown file once it’s removed.

One option is to use a shortcode. So instead of this unpreferable way that you mentioned:

![alt](/gg/image/test.jpg)

You could do:

{{< img "alt" "image/test.jpg" >}}

And the shortcode definition (let’s say it’s named img.html) could be like:

<img src="/gg/{{ .Get 1 }}" alt="{{ .Get 0 }}">

Or:

<img src="{{ .Get 1 | absURL }}" alt="{{ .Get 0 }}">

I think this guy has it right:

Add the <base> tag into <head> :

<base href="{{ .Site.BaseURL }}">

And then you can insert image in post like this:

![Foo image](img/foo.jpg)

(for files in /static/img in this case)