This commit is contained in:
Christoph Cullmann 2025-07-15 22:39:24 +02:00
parent 7979c40554
commit c2189ef133
No known key found for this signature in database
540 changed files with 6036 additions and 29285 deletions

View file

@ -1,31 +0,0 @@
{{ $id := delimit (slice "gallery" (partial "functions/uid.html" .)) "-" }}
<div id="{{ $id }}" class="gallery">
{{ $page := .Page }}
{{/* find all img tags */}}
{{ $imgTagRegex := `<img\s+[^>]*>` }}
{{ $imgTags := findRE $imgTagRegex .Inner }}
{{ $newContent := .Inner }}
{{ range $imgTags }}
{{ $imgTag := . }}
{{/* extract src attribute */}}
{{ $srcRegex := `src=['"]([^'"]+)['"]` }}
{{ $srcMatches := findRESubmatch $srcRegex $imgTag }}
{{ if $srcMatches }}
{{ $srcFull := index (index $srcMatches 0) 0 }}
{{ $src := index (index $srcMatches 0) 1 }}
{{ $resource := $page.Resources.GetMatch $src }}
{{ if $resource }}
{{ $newSrc := printf `src="%s"` $resource.RelPermalink }}
{{ $newImg := replace $imgTag $srcFull $newSrc }}
{{ $newContent = replace $newContent $imgTag $newImg }}
{{ end }}
{{ end }}
{{ end }}
{{ $newContent | safeHTML }}
</div>