mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 07:47:54 +00:00
image: support Markdown attributes #795
This commit is contained in:
parent
d81b4dd6eb
commit
518ffb09df
4 changed files with 30 additions and 8 deletions
|
@ -7,7 +7,7 @@ A theme for [Hugo](https://gohugo.io/) designed for documentation.
|
||||||
|
|
||||||
[★ What's new in the latest release ★](basics/migration)
|
[★ What's new in the latest release ★](basics/migration)
|
||||||
|
|
||||||
![Image of the Relearn theme in light and dark mode on phone, tablet and desktop](/images/hero.png?width=100%&height=100%)
|
![Image of the Relearn theme in light and dark mode on phone, tablet and desktop](/images/hero.png)
|
||||||
|
|
||||||
## Motivation
|
## Motivation
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ The location is mandatory due to Hugo's theme site builder.
|
||||||
|
|
||||||
**Preview** `images/screenshot.png`:
|
**Preview** `images/screenshot.png`:
|
||||||
|
|
||||||
![Screenshot](/images/screenshot.png?width=100%25&height=100%25)
|
![Screenshot](/images/screenshot.png?width=50%25&height=50%25)
|
||||||
|
|
||||||
## Hero Image
|
## Hero Image
|
||||||
|
|
||||||
|
@ -80,8 +80,8 @@ The location of `images/tn.png` is mandatory due to Hugo's theme site builder.
|
||||||
|
|
||||||
**Preview** `images/hero.png`:
|
**Preview** `images/hero.png`:
|
||||||
|
|
||||||
![Hero](/images/hero.png?width=100%25&height=100%25)
|
![Hero](/images/hero.png?width=50%25&height=50%25)
|
||||||
|
|
||||||
**Preview** `images/tn.png`:
|
**Preview** `images/tn.png`:
|
||||||
|
|
||||||
![tn](/images/tn.png?width=100%25&height=100%25)
|
![tn](/images/tn.png?width=50%25&height=50%25)
|
||||||
|
|
|
@ -5,4 +5,5 @@
|
||||||
"title" .Title
|
"title" .Title
|
||||||
"alt" .Text
|
"alt" .Text
|
||||||
"id" $id
|
"id" $id
|
||||||
|
"attributes" .Attributes
|
||||||
) }}
|
) }}
|
|
@ -19,7 +19,10 @@
|
||||||
{{- $dest_path := $dest_url.Path }}
|
{{- $dest_path := $dest_url.Path }}
|
||||||
{{- $image := "" }}
|
{{- $image := "" }}
|
||||||
{{- if not $dest_url.IsAbs }}
|
{{- if not $dest_url.IsAbs }}
|
||||||
{{- with or ($page.Resources.Get $dest_url.Path) (resources.Get $dest_url.Path) }}
|
{{- with or
|
||||||
|
($page.Resources.Get $dest_url.Path)
|
||||||
|
(resources.Get $dest_url.Path)
|
||||||
|
}}
|
||||||
{{- $image = . }}
|
{{- $image = . }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- with $image }}
|
{{- with $image }}
|
||||||
|
@ -27,6 +30,9 @@
|
||||||
{{- with $dest_url.RawQuery }}
|
{{- with $dest_url.RawQuery }}
|
||||||
{{- $url = printf "%s?%s" $url . }}
|
{{- $url = printf "%s?%s" $url . }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- with $dest_url.Fragment }}
|
||||||
|
{{- $url = printf "%s#%s" $url . }}
|
||||||
|
{{- end }}
|
||||||
{{- else }}
|
{{- else }}
|
||||||
{{- if eq $page.Site.Params.image.errorlevel "warning" }}
|
{{- if eq $page.Site.Params.image.errorlevel "warning" }}
|
||||||
{{- warnf "%q: image '%s' is not a resource but linked anyways" $page.File.Filename .url }}
|
{{- warnf "%q: image '%s' is not a resource but linked anyways" $page.File.Filename .url }}
|
||||||
|
@ -69,12 +75,27 @@
|
||||||
{{- $c := printf "%s%s" (cond $v "" "no") $k }}
|
{{- $c := printf "%s%s" (cond $v "" "no") $k }}
|
||||||
{{- $classes = $classes | append $c }}
|
{{- $classes = $classes | append $c }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- $attributes := merge .attributes (dict "alt" $alt "src" $url "title" $title "loading" "lazy") }}
|
||||||
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo" $page) .id }}
|
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo" $page) .id }}
|
||||||
{{- if $effects.lightbox -}}
|
{{- if $effects.lightbox -}}
|
||||||
<a href="#R-image-{{ $id }}" class="lightbox-link">
|
<a href="#R-image-{{ $id }}" class="lightbox-link">
|
||||||
{{- end -}}
|
{{- end }}
|
||||||
<img src="{{ $url | safeURL }}" alt="{{ $alt }}"{{ with $title }} title="{{ . }}"{{ end }} class="figure-image {{ delimit $classes " " }}" style="height: {{ $height }}; width: {{ $width }};" loading="lazy">
|
{{- $attributes_figure := merge $attributes (dict "class" (delimit (append (index $attributes "class" | default slice) "figure-image" $classes) " ")) }}
|
||||||
|
{{- $attributes_figure = merge $attributes_figure (dict "style" (delimit (slice (index $attributes "style") (printf "height: %s; width: %s;" $height $width)) " ")) -}}
|
||||||
|
<img
|
||||||
|
{{- range $k, $v := $attributes_figure }}
|
||||||
|
{{- if $v }}
|
||||||
|
{{- printf " %s=%q" $k $v | safeHTMLAttr }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}>
|
||||||
{{- if $effects.lightbox -}}
|
{{- if $effects.lightbox -}}
|
||||||
</a>
|
</a>
|
||||||
<a href="javascript:history.back();" class="lightbox-back" id="R-image-{{ $id }}"><img src="{{ $url | safeURL }}" alt="{{ $alt }}"{{ with $title }} title="{{ . }}"{{ end }} class="lightbox-image {{ delimit $classes " " }}" loading="lazy"></a>
|
<a href="javascript:history.back();" class="lightbox-back" id="R-image-{{ $id }}">
|
||||||
|
{{- $attributes_lightbox := merge $attributes (dict "class" (delimit (append (index $attributes "class" | default slice) "lightbox-image" $classes) " ")) -}}
|
||||||
|
<img
|
||||||
|
{{- range $k, $v := $attributes_lightbox }}
|
||||||
|
{{- if $v }}
|
||||||
|
{{- printf " %s=%q" $k $v | safeHTMLAttr }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}></a>
|
||||||
{{- end }}
|
{{- end }}
|
Loading…
Reference in a new issue