diff --git a/exampleSite/content/en/shortcodes/avatar/_index.md b/exampleSite/content/en/shortcodes/avatar/_index.md new file mode 100644 index 0000000..6d9a3fc --- /dev/null +++ b/exampleSite/content/en/shortcodes/avatar/_index.md @@ -0,0 +1,46 @@ +--- +title: Avatar +resources: + - name: avatar + src: "avatar.jpg" + title: "Avatar" +--- + +The avatar shortcode is another custom image shortcode. + + + +## Usage + +Define a resource in the page front matter. + + + +```md +--- +resources: + - name: avatar + src: "images/avatar.jpg" + title: "Avatar" +--- + +{{}} +``` + + + +## Attributes + + + +{{< propertylist name=shortcode-avatar sort=name order=asc >}} + + + +## Example + + + +{{< avatar name=avatar size="small" >}} + + diff --git a/exampleSite/content/en/shortcodes/avatar/avatar.jpg b/exampleSite/content/en/shortcodes/avatar/avatar.jpg new file mode 100644 index 0000000..d0fc747 Binary files /dev/null and b/exampleSite/content/en/shortcodes/avatar/avatar.jpg differ diff --git a/exampleSite/data/properties/shortcode-avatar.yaml b/exampleSite/data/properties/shortcode-avatar.yaml new file mode 100644 index 0000000..1224783 --- /dev/null +++ b/exampleSite/data/properties/shortcode-avatar.yaml @@ -0,0 +1,18 @@ +--- +properties: + - name: name + type: string + description: Name of the image resource defined in page front matter. + required: true + - name: alt + type: string + description: Description text for the image. + required: false + - name: size + type: string + description: Thumbnail size. Supported values are `origin|tiny|small|medium|large`. + required: false + - name: anchor + type: string + description: "[Anchor](https://gohugo.io/content-management/image-processing/#anchor) to determine the placement of the crop box." + required: false diff --git a/exampleSite/data/properties/shortcode-images.yaml b/exampleSite/data/properties/shortcode-images.yaml index be5efa6..a3d3f15 100644 --- a/exampleSite/data/properties/shortcode-images.yaml +++ b/exampleSite/data/properties/shortcode-images.yaml @@ -2,7 +2,7 @@ properties: - name: name type: string - description: Mame of the image resource defined in page front matter. + description: Name of the image resource defined in page front matter. required: true - name: alt type: string @@ -10,7 +10,7 @@ properties: required: false - name: size type: string - description: Thumbnail size. Supported values are `origin|profile|tiny|small|medium|large`. + description: Thumbnail size. Supported values are `origin|tiny|small|medium|large`. required: false - name: lazy type: bool diff --git a/layouts/shortcodes/avatar.html b/layouts/shortcodes/avatar.html new file mode 100644 index 0000000..1d64429 --- /dev/null +++ b/layouts/shortcodes/avatar.html @@ -0,0 +1,57 @@ +{{- $source := ($.Page.Resources.ByType "image").GetMatch (printf "%s" (.Get "name")) }} +{{- $customAlt := .Get "alt" }} +{{- $customSize := .Get "size" | lower }} +{{- $customAnchor := default "smart" (.Get "anchor") | title }} +{{- $data := newScratch }} + +{{- with $source }} + {{- $caption := default .Title $customAlt }} + {{- $isSVG := (eq .MediaType.SubType "svg") }} + {{- $origin := . -}} + + {{- if $isSVG }} + {{- $data.SetInMap "size" "tiny" "160" }} + {{- $data.SetInMap "size" "small" "300" }} + {{- $data.SetInMap "size" "medium" "600" }} + {{- $data.SetInMap "size" "large" "900" }} + {{- else }} + {{- $data.SetInMap "size" "tiny" (printf "160x160 %s" $customAnchor) }} + {{- $data.SetInMap "size" "small" (printf "300x300 %s" $customAnchor) }} + {{- $data.SetInMap "size" "medium" (printf "600x600 %s" $customAnchor) }} + {{- $data.SetInMap "size" "large" (printf "900x900 %s" $customAnchor) }} + {{- end -}} + +
+
+ + + {{- $size := $data.Get "size" }} + {{- if not $isSVG }} + {{- if ne $customSize "origin" }} + + {{- end }} + {{- end }} + {{ $caption }} + + +
+
+{{- end }} diff --git a/layouts/shortcodes/img.html b/layouts/shortcodes/img.html index 4490e5f..f0bbb6b 100644 --- a/layouts/shortcodes/img.html +++ b/layouts/shortcodes/img.html @@ -7,40 +7,30 @@ {{- with $source }} {{- $caption := default .Title $customAlt }} {{- $isSVG := (eq .MediaType.SubType "svg") }} - {{- $origin := . }} + {{- if $isSVG }} - {{- $data.SetInMap "size" "profile" "180" }} {{- $data.SetInMap "size" "tiny" "320" }} {{- $data.SetInMap "size" "small" "600" }} {{- $data.SetInMap "size" "medium" "1200" }} {{- $data.SetInMap "size" "large" "1800" }} {{- else }} - {{- $data.SetInMap "size" "profile" "180x180 Center" }} {{- $data.SetInMap "size" "tiny" "320x"}} {{- $data.SetInMap "size" "small" "600x" }} {{- $data.SetInMap "size" "medium" "1200x" }} {{- $data.SetInMap "size" "large" "1800x" }} - {{- end }} - + {{- end -}}
-
+
{{- $size := $data.Get "size" }} {{- if not $isSVG }} {{- if ne $customSize "origin" }} - {{- if not (eq $customSize "profile") }} - {{- with $caption }} -
- {{ . }} - {{- with $source.Params.credits }} - {{ printf " (%s)" . | $.Page.RenderString }} - {{- end }} -
- {{- end }} + {{- with $caption }} +
+ {{ . }} + {{- with $source.Params.credits }} + {{ printf " (%s)" . | $.Page.RenderString }} + {{- end }} +
{{- end }}