mirror of
https://gitee.com/butubb8/blowfish.git
synced 2025-12-05 14:17:50 +08:00
44 lines
1.3 KiB
HTML
44 lines
1.3 KiB
HTML
{{ $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 -}}
|
|
|
|
{{ $finalSrc := $src -}}
|
|
{{ $isExternalURL := or (hasPrefix $src "http://") (hasPrefix $src "https://") -}}
|
|
|
|
{{ if $isExternalURL -}}
|
|
{{ with resources.GetRemote $src -}}{{ $finalSrc = .RelPermalink -}}{{ end -}}
|
|
{{ else -}}
|
|
{{ with $page.Resources.GetMatch $src -}}
|
|
{{ $finalSrc = .RelPermalink -}}
|
|
{{ else -}}
|
|
{{ with resources.GetMatch $src -}}{{ $finalSrc = .RelPermalink }}{{ end -}}
|
|
{{ end -}}
|
|
{{ end -}}
|
|
|
|
{{ $newSrc := printf `src="%s"` $finalSrc -}}
|
|
{{ $newImg := replace $imgTag $srcFull $newSrc -}}
|
|
{{ $newContent = replace $newContent $imgTag $newImg -}}
|
|
{{ end -}}
|
|
{{ end -}}
|
|
|
|
{{ $newContent | safeHTML -}}
|
|
</div>
|