-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{{/* this is meant to take the place of resource-image | ||
it is not a drop-in for resrouce image, because it uses WIDTH not SIZE | ||
we need to use WIDTH since we need it for the caption | ||
|
||
it takes the place of figure (in that it allows for a caption), but allows for the resource finding and re-sizing of resource-image | ||
|
||
this whole thing was caused by the need to have the caption sized to the width of the image (since the captions look stupid otherwise) | ||
|
||
the argugements are: | ||
src - the reource name | ||
width - target width (default 300) - height is auto | ||
alt - alt text (default is the resource name) | ||
class - class for the figure (default is "") | ||
caption - caption for the image (default is "") | ||
attr - attribution for the image (default is "") | ||
attrlink - link for the attribution (default is "") | ||
|
||
*/}} | ||
{{- $page := . }} | ||
{{- $name := .Get "src" }} | ||
{{- if $name }}{{- else }}{{errorf "resource-image needs a src argument" }}{{- end}} | ||
{{- $width := .Get "width" | default "300" }} | ||
{{- $size := (printf "%vx%v" $width 5000) }} | ||
{{- $alt := .Get "alt" | default $name }} | ||
{{- $class := .Get "class" | default "" }} | ||
{{- $local := .Page.Resources.GetMatch $name }} | ||
{{- $global := resources.GetMatch $name}} | ||
{{- $img := $local | default $global -}} | ||
{{- $caption := .Get "caption" | default "" }} | ||
{{- $attr := .Get "attr" | default "" }} | ||
{{- $attrlink := .Get "attrlink" | default "" }} | ||
{{- if (.Get "size") }}{{ errorf "rimage does not allow size - use width"}}{{end -}} | ||
{{- with $img }} | ||
{{ $img := .Fit $size }} | ||
<figure class="{{ $class }}" style="width: {{ $width }}px;"> | ||
<a href="{{ .RelPermalink }}"> | ||
<img src="{{ $img.RelPermalink }}" alt="{{ $alt }}" /> | ||
</a> | ||
{{- if or $caption $attr -}}<figcaption><p> | ||
{{- $caption | markdownify -}} | ||
{{- with $attrlink }} | ||
<a href="{{ . }}"> | ||
{{- end -}} | ||
{{- $attr | markdownify -}} | ||
{{- if $attrlink }}</a>{{ end }}</p></figcaption> | ||
{{- end }} | ||
</figure> | ||
{{- else}} | ||
{{ errorf "resource-image couldn't open '%s':" $name -}} | ||
{{- end}} |