Hi, iam having some isues with Hugo’s built-in figure shortcodes.
i haved added several figure shortcodes to files .md using i.e.:
{{< figure src=“img/pandas_14.jpg” >}}
but when i run hugo, it’s not capable to add the baseURL path to the img-output.html
I’ve put all the path (baseURL included) in the figure shortcodes to create the site with hugo and it’s worked…(but iam not been able to see the image when iam creating new .md files)
<figure{{ with .Get "class" }} class="{{ . }}"{{ end }}>
{{- if .Get "link" -}}
<a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}>
{{- end -}}
<img src="{{ .Get "src" }}"
{{- if or (.Get "alt") (.Get "caption") }}
alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" | markdownify| plainify }}{{ end }}"
{{- end -}}
{{- with .Get "width" }} width="{{ . }}"{{ end -}}
{{- with .Get "height" }} height="{{ . }}"{{ end -}}
/><!-- Closing img tag -->
{{- if .Get "link" }}</a>{{ end -}}
{{- if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}}
<figcaption>
{{ with (.Get "title") -}}
<h4>{{ . }}</h4>
{{- end -}}
{{- if or (.Get "caption") (.Get "attr") -}}<p>
{{- .Get "caption" | markdownify -}}
{{- with .Get "attrlink" }}
<a href="{{ . }}">
{{- end -}}
{{- .Get "attr" | markdownify -}}
{{- if .Get "attrlink" }}</a>{{ end }}</p>
{{- end }}
</figcaption>
{{- end }}
</figure>
Will have a look if I or somebody else managed to provide output with an absolute URL, but do you really need that? Heres why.
This shortcode will work in post folder structure. Each image will be in img folder that is down in post folder.
For example, if you got /posts/my-first-post/index.md than img/pandas_14.jpg will refers to http://localhost:1313/posts/my-first-post/img/pandas_14.jpg.
Cannot just add absURL (<img src="{{ .Get "src" | absURL }}") as than this will refers to files stored directly in your content and there img folder http://localhost:1313/img/pandas_14.jpg.