tpl: Add imageConfig function

Add imageConfig function which calls image.DecodeConfig and returns the height, width and color mode of the image. (#2677)

This allows for more advanced image shortcodes and templates such as those required by AMP.

layouts/shortcodes/amp-img.html
```
{{ $src := .Get "src" }}
{{ $config := imageConfig (printf "/static/%s" $src) }}

<amp-img src="{{$src}}"
           height="{{$config.Height}}"
           width="{{$config.Width}}"
           layout="responsive">
</amp-img>
```
This commit is contained in:
Tristan Rice
2016-11-16 04:00:45 -08:00
committed by Bjørn Erik Pedersen
parent 950034db5c
commit a49f838cd0
4 changed files with 184 additions and 2 deletions

View File

@@ -120,12 +120,14 @@ func (h *HugoSites) getNodes(nodeID string) Nodes {
return Nodes{}
}
// Reset resets the sites, making it ready for a full rebuild.
// Reset resets the sites and template caches, making it ready for a full rebuild.
func (h *HugoSites) reset() {
h.nodeMap = make(map[string]Nodes)
for i, s := range h.Sites {
h.Sites[i] = s.reset()
}
tpl.ResetCaches()
}
func (h *HugoSites) reCreateFromConfig() error {