diff --git a/hugo.toml b/hugo.toml index a697e6188bb3..a76a15dbe02a 100644 --- a/hugo.toml +++ b/hugo.toml @@ -348,6 +348,14 @@ enable = false [[module.imports]] path = "github.com/google/docsy/dependencies" disable = false + [[module.mounts]] + source = "assets" + target = "assets" + # Content images are mounted into assets so the image render hook can + # process them (Hugo can only process files that are resources). + [[module.mounts]] + source = "content/en" + target = "assets/contentimg" [[module.mounts]] source = "static" target = "static" diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index f5ab8e99ada3..34af92caad01 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -1,14 +1,44 @@ - - + +{{- $dest := .Destination -}} +{{- $alt := .Text -}} +{{- $class := "md-image-responsive" -}} +{{- with .Title }}{{ $class = printf "md-image-responsive %s" . }}{{ end -}} +{{- $img := "" -}} +{{- $ext := lower (path.Ext $dest) -}} + +{{- if and (in (slice ".png" ".jpg" ".jpeg") $ext) (not (urls.Parse $dest).Scheme) (not (hasPrefix $dest "//")) -}} + {{- $rel := $dest -}} + {{- if not (hasPrefix $dest "/") -}} + {{- with .Page.File -}} + {{- $rel = path.Join (replace .Dir "\\" "/") $dest -}} + {{- end -}} + {{- end -}} + {{- $img = resources.Get (path.Join "contentimg" $rel) -}} + {{- if not $img -}}{{- $img = resources.Get $rel -}}{{- end -}} +{{- end -}} +