您需要确保已将图片包含在页面内容中,通常是在页面本身级别,除非您使用下面注释中的答案 I 链接来引用它们。
注意:您可以通过in this answer从外部部分访问资源
写一个简码
layouts/shortcodes/imgresize.html
{{ $original := .Page.Resources.GetByPrefix (.Get 0) }}
{{ $options := .Get 1 }}
{{ .Scratch.Set "image" ($original.Resize $options) }}
{{ $image := .Scratch.Get "image" }}
<img src="{{ $image.RelPermalink }}" width="{{ $image.Width }}" height="{{ $image.Height }}">
[Alternative] 短代码访问content/media 部分下的资源
{{ $imagename := (.Get 0) }}
{{ $options := .Get 1 }}
{{ with .Site.GetPage "section" "media" }}
{{ $original := .Resources.GetByPrefix $imagename }}
{{ with ($original.Resize $options) }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}">
{{ end }}
{{ end }}
在页面的 markdown 中调用简码。
{{< imgresize pdf "50x50" >}}
pdf通过名称前缀引用图片来获取资源。
使用子文件夹页面访问资源
在下一个示例短代码中,您的页面必须与您的图片处于同一级别。在同一级别包含一个 index.md(例如:content/media/logos/index.md)
添加layouts/shortcodes/logo-resize.html
{{ $imagename := (.Get 0) }}
{{ $options := .Get 1 }}
{{ with .Site.GetPage "page" "media/logos/index.md" }}
{{ $original := .Resources.GetByPrefix $imagename }}
{{ with ($original.Resize $options) }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}">
{{ end }}
{{ end }}
调用简码
{{< logo-resize pdf "50x50" >}}