{{- $page := . -}} {{- $bundleImages := slice -}} {{- range $page.Resources.ByType "image" -}} {{- if strings.HasPrefix .Name "images/" -}} {{- $bundleImages = $bundleImages | append . -}} {{- end -}} {{- end -}} {{- if gt (len $bundleImages) 0 -}} {{- $coverPath := "" -}} {{- with $page.Params.cover -}} {{- $coverPath = strings.TrimSpace (printf "%v" .) -}} {{- end -}} {{- $coverImagePath := "" -}} {{- if ne $coverPath "" -}} {{- $coverPathLower := lower $coverPath -}} {{- if or (strings.HasSuffix $coverPathLower ".yaml") (strings.HasSuffix $coverPathLower ".yml") -}} {{- $coverDataFile := $page.Resources.GetMatch $coverPath -}} {{- if $coverDataFile -}} {{- with $coverDataFile.Content | transform.Unmarshal -}} {{- with index . "file" -}} {{- $coverImagePath = strings.TrimSpace (printf "%v" .) -}} {{- end -}} {{- end -}} {{- end -}} {{- else -}} {{- $coverImagePath = $coverPath -}} {{- end -}} {{- end -}} {{- $coverImageName := "" -}} {{- if ne $coverImagePath "" -}} {{- $coverImageName = lower (path.Base ((urls.Parse $coverImagePath).Path)) -}} {{- $coverImageName = replace $coverImageName "%20" " " -}} {{- end -}} {{- $contentImageNames := slice -}} {{- $contentImageStems := slice -}} {{- $imageTags := findRE `(?is)]+src=["'][^"']+["'][^>]*>` .Content -}} {{- range $imageTags -}} {{- $srcMatch := findRESubmatch `(?is)src=["']([^"']+)["']` . -}} {{- if gt (len $srcMatch) 0 -}} {{- $srcRaw := index (index $srcMatch 0) 1 -}} {{- $srcPath := (urls.Parse $srcRaw).Path -}} {{- $src := lower $srcPath -}} {{- if or (in $src "/images/") (strings.HasPrefix $src "images/") (strings.HasPrefix $src "./images/") -}} {{- $srcName := lower (path.Base $srcPath) -}} {{- $srcName = replace $srcName "%20" " " -}} {{- $srcName = replaceRE "\\?.*$" "" $srcName -}} {{- $srcName = replaceRE "#.*$" "" $srcName -}} {{- $srcName = replaceRE "_hu_[^.]*" "" $srcName -}} {{- $srcStem := $srcName | replaceRE "\\.[^.]+$" "" -}} {{- $contentImageNames = $contentImageNames | append $srcName -}} {{- $contentImageStems = $contentImageStems | append $srcStem -}} {{- end -}} {{- end -}} {{- end -}} {{- $unusedImages := slice -}} {{- range $bundleImages -}} {{- $imageName := path.Base .Name -}} {{- $imageNameLower := lower $imageName -}} {{- $isCoverImage := false -}} {{- if and (ne $coverImageName "") (eq $imageNameLower $coverImageName) -}} {{- $isCoverImage = true -}} {{- end -}} {{- if not $isCoverImage -}} {{- $imageStem := $imageName | replaceRE "\\.[^.]+$" "" -}} {{- $imageStemLower := lower $imageStem -}} {{- $isUsedInContent := false -}} {{- range $contentImageNames -}} {{- if eq . $imageNameLower -}} {{- $isUsedInContent = true -}} {{- end -}} {{- end -}} {{- if not $isUsedInContent -}} {{- range $contentImageStems -}} {{- if eq . $imageStemLower -}} {{- $isUsedInContent = true -}} {{- end -}} {{- end -}} {{- end -}} {{- if not $isUsedInContent -}} {{- $unusedImages = $unusedImages | append . -}} {{- end -}} {{- end -}} {{- end -}} {{- if gt (len $unusedImages) 0 -}}

Fichiers complémentaires

{{- end -}} {{- end -}}