mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 07:47:54 +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
|
||||
"title" .Title
|
||||
"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 }}
|
||||
{{- $title := .title }}
|
||||
{{- $alt := .alt }}
|
||||
{{- $ordinal := .ordinal }}
|
||||
{{- $classes := slice }}
|
||||
{{- $lightbox := true }}
|
||||
{{- $height := "auto" }}
|
||||
|
@ -34,14 +33,14 @@
|
|||
{{ $width = . }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- $fragment := printf "%d-%s" $ordinal ((trim (replace (replace (replace (replace (replace $url "=" "-") "&" "-") "?" "-") "." "-") "/" "-") "-") | safeURL | anchorize) }}
|
||||
{{- $id := partial "make-random-md5.hugo" }}
|
||||
{{- if $lightbox }}
|
||||
<a href="#{{ $fragment }}">
|
||||
<a href="#{{ $id }}">
|
||||
{{- 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">
|
||||
{{- if $lightbox }}
|
||||
</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">
|
||||
</a>
|
||||
{{- end }}
|
Loading…
Reference in a new issue