mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 15:57:57 +00:00
lightbox: generate unique lightbox ids #451
This commit is contained in:
parent
f89c9944bd
commit
1383b7e6af
3 changed files with 11 additions and 5 deletions
|
@ -3,5 +3,4 @@
|
||||||
"url" .Destination
|
"url" .Destination
|
||||||
"title" .Title
|
"title" .Title
|
||||||
"alt" .Text
|
"alt" .Text
|
||||||
"ordinal" 0
|
|
||||||
) }}
|
) }}
|
8
layouts/partials/make-random-md5.hugo
Normal file
8
layouts/partials/make-random-md5.hugo
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{{- $random := "" }}
|
||||||
|
{{- $set := split "012345abcdefghijklmnopqrstuvwxyz" "" }}
|
||||||
|
{{- range (seq 16) }}
|
||||||
|
{{- with ($set | shuffle | first 1) }}
|
||||||
|
{{- $random = printf "%s%s" $random . }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- md5 $random }}
|
|
@ -2,7 +2,6 @@
|
||||||
{{- $url := .url }}
|
{{- $url := .url }}
|
||||||
{{- $title := .title }}
|
{{- $title := .title }}
|
||||||
{{- $alt := .alt }}
|
{{- $alt := .alt }}
|
||||||
{{- $ordinal := .ordinal }}
|
|
||||||
{{- $classes := slice }}
|
{{- $classes := slice }}
|
||||||
{{- $lightbox := true }}
|
{{- $lightbox := true }}
|
||||||
{{- $height := "auto" }}
|
{{- $height := "auto" }}
|
||||||
|
@ -34,14 +33,14 @@
|
||||||
{{ $width = . }}
|
{{ $width = . }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- $fragment := printf "%d-%s" $ordinal ((trim (replace (replace (replace (replace (replace $url "=" "-") "&" "-") "?" "-") "." "-") "/" "-") "-") | safeURL | anchorize) }}
|
{{- $id := partial "make-random-md5.hugo" }}
|
||||||
{{- if $lightbox }}
|
{{- if $lightbox }}
|
||||||
<a href="#{{ $fragment }}">
|
<a href="#{{ $id }}">
|
||||||
{{- end }}
|
{{- end }}
|
||||||
<img src="{{ $url | safeURL }}" alt="{{ $alt }}"{{ with $title }} title="{{ . }}"{{ end }}{{ if len ($classes) }} class="{{ delimit $classes " " }}"{{ end }} style="height: {{ $height }}; width: {{ $width }};" loading="lazy">
|
<img src="{{ $url | safeURL }}" alt="{{ $alt }}"{{ with $title }} title="{{ . }}"{{ end }}{{ if len ($classes) }} class="{{ delimit $classes " " }}"{{ end }} style="height: {{ $height }}; width: {{ $width }};" loading="lazy">
|
||||||
{{- if $lightbox }}
|
{{- if $lightbox }}
|
||||||
</a>
|
</a>
|
||||||
<a href="javascript:history.back();" class="lightbox" id="{{ $fragment }}">
|
<a href="javascript:history.back();" class="lightbox" id="{{ $id }}">
|
||||||
<img src="{{ $url | safeURL }}" alt="{{ $alt }}"{{ with $title }} title="{{ . }}"{{ end }}loading="lazy">
|
<img src="{{ $url | safeURL }}" alt="{{ $alt }}"{{ with $title }} title="{{ . }}"{{ end }}loading="lazy">
|
||||||
</a>
|
</a>
|
||||||
{{- end }}
|
{{- end }}
|
Loading…
Reference in a new issue