From 9adee7c9aeaf746246acbfa0efe5497c5563612f Mon Sep 17 00:00:00 2001 From: Julio Pescador Date: Fri, 26 Feb 2016 15:47:41 -0800 Subject: Can now add alt text to an image The alt text value can be provided in the intro pic by setting the site param: [params.intro.pic] alt = "set text" The shortcodes img-fit and img-post can now set the alt text value. The parameter for img-post is the last position or the named parameter alt. Here is an example for both: {{< img-post "date" "file.jpg" "left" "alt text" >}} {{< img-post path="date" file="file.jpg" type="left" alt="text" >}} img-fit has changed slightly. The first parameter will not be the path. Instead, that will always be the last parameter. You still have the ability to place as many images as needed in this shortcode call. postion: 0: width of column 1-12 in u or u$ 1: filename including extension 2: alt text 3: same as pos 0 4: same as pos 1 5: same as pos 2 ... n-3 n-2 n-1 n: name of the path --- layouts/partials/sidebar.html | 6 ++++-- layouts/shortcodes/img-fit.html | 44 ++++++++++++++++++++++++++------------ layouts/shortcodes/img-post.html | 46 +++++++++++++++++++++------------------- 3 files changed, 58 insertions(+), 38 deletions(-) diff --git a/layouts/partials/sidebar.html b/layouts/partials/sidebar.html index 53390fa..e8fbf9e 100644 --- a/layouts/partials/sidebar.html +++ b/layouts/partials/sidebar.html @@ -6,9 +6,11 @@ {{ $pic := .Site.Params.intro.pic }} {{ with $pic.src }} {{ if $pic.circle }} - + {{ $pic.alt }} + {{ else if $pic.imperfect }} + {{ else }} - + {{ $pic.alt }} {{ end }} {{ end }}
diff --git a/layouts/shortcodes/img-fit.html b/layouts/shortcodes/img-fit.html index 1b34ef6..70b4a69 100644 --- a/layouts/shortcodes/img-fit.html +++ b/layouts/shortcodes/img-fit.html @@ -1,37 +1,45 @@ - -{{ $numOfParams := len .Params }} +{{ $numOfParams := sub (len .Params) 1 }} {{ if and (ge $numOfParams 3) (not (modBool $numOfParams 2)) }} - {{ $.Scratch.Set "path" (.Get 0) }} + {{ $.Scratch.Set "path" (.Get $numOfParams) }} {{ $.Scratch.Set "structType" "shortcode" }} {{ partial "img-path" . }} @@ -40,17 +48,25 @@
{{ $.Scratch.Set "count" 1 }} - {{ range after 1 .Params }} - {{ if not (modBool ($.Scratch.Get "count") 2) }} + {{ $.Scratch.Set "imgFile" "" }} + {{ range first $numOfParams .Params }} + {{ if eq ($.Scratch.Get "count") 1 }}
- {{ else }} + {{ else if eq ($.Scratch.Get "count") 2 }} {{ if eq . "" }}
+ {{ $.Scratch.Set "imgFile" "" }} {{ else }} + {{ $.Scratch.Set "imgFile" . }} - + {{ end }} + {{ else }} + {{ if ne ($.Scratch.Get "imgFile") "" }} + {{ . }}
{{ end }} + {{ $.Scratch.Set "count" 0 }} {{ end }} {{ $.Scratch.Add "count" 1 }} {{ end }} diff --git a/layouts/shortcodes/img-post.html b/layouts/shortcodes/img-post.html index 9f418ce..f2e50bb 100644 --- a/layouts/shortcodes/img-post.html +++ b/layouts/shortcodes/img-post.html @@ -1,6 +1,6 @@ {{ $numOfParams := len .Params }} -{{ if and (ge $numOfParams 2) (le $numOfParams 3) }} +{{ if and (ge $numOfParams 2) (le $numOfParams 4) }} {{ if .IsNamedParams }} {{ $.Scratch.Set "path" (.Get "path") }} {{ $.Scratch.Set "file" (.Get "file") }} - - {{ if eq $numOfParams 2 }} - {{ $.Scratch.Set "type" "post" }} - {{ else }} - {{ $.Scratch.Set "type" (.Get "type") }} - {{ end }} + {{ $.Scratch.Set "type" (.Get "type") }} + {{ $.Scratch.Set "alt" (.Get "alt") }} {{ else }} - {{ $.Scratch.Set "path" (.Get 0) }} - {{ $.Scratch.Set "file" (.Get 1) }} - - {{ if eq $numOfParams 2 }} - {{ $.Scratch.Set "type" "post" }} - {{ else }} - {{ $.Scratch.Set "type" (.Get 2) }} + {{ if ge $numOfParams 2 }} + {{ $.Scratch.Set "path" (.Get 0) }} + {{ $.Scratch.Set "file" (.Get 1) }} + {{ if ge $numOfParams 3 }} + {{ $.Scratch.Set "type" (.Get 2) }} + {{ end }} + {{ if ge $numOfParams 4 }} + {{ $.Scratch.Set "alt" (.Get 3) }} + {{ end }} {{ end }} {{ end }} {{ $file := $.Scratch.Get "file" }} {{ $type := $.Scratch.Get "type" }} + {{ $alt := $.Scratch.Get "alt" }} {{ $.Scratch.Set "structType" "shortcode" }} {{ partial "img-path" . }} {{ $path := $.Scratch.Get "path" }} - {{ if eq $type "post" }} -
- -
- {{ else if eq $type "left" }} + {{ if eq $type "left" }} - + {{ $alt }} {{ else if eq $type "right" }} - + {{ $alt }} + {{ else }} +
+ {{ $alt }} +
{{ end }} {{ end }} -- cgit v1.2.3