We use render hooks for images (_markup\render-image.html
) to modify the path of the image so that it is compatible with the editor we use (Typora). The goal is that the path is correct, both in edit mode within Typora and of course later on the published page.
Typora is set up to copy images to ./media
when an image is pasted in edit mode. On the published page, the image path must be altered depending on the page being a .IsNode
or not.
We also add a no-scale
class to the rendered image if #ns
was added to src in edit mode.
Here’s the code sample
{{ $pathPrefix := "../" }}
{{ if .Page.IsNode }}
{{ $pathPrefix = "" }}
{{ end }}
{{ $ts := split .Destination "#" }}
{{ $tDestination := index $ts 0 }}
{{ $class := index $ts 1 }}
{{ if eq $class "ns" }}
{{ $class = "no-scale" }}
{{ end }}
<img src="{{ .Page.Permalink }}{{ $pathPrefix }}{{ $tDestination | safeURL}}" {{ with .Text}} alt="{{ . }}"{{ end }} {{ with $class}} class="{{ . }}"{{ end }} />
This works great for images.
We’d love to have the same for videos. There is currently no need for adding additional classes. But src
is broken and must be altered on the published page.
Is there currently a way of doing that? There is no render hook (Markdown render hooks | Hugo) for video. Can this be added in the future?
I wanted to discuss here before adding a proposal in GitHub.