Extraire les partiels de calcul du thème 2026
This commit is contained in:
19
layouts/partials/media/parse-attribution.html
Normal file
19
layouts/partials/media/parse-attribution.html
Normal file
@@ -0,0 +1,19 @@
|
||||
{{- $raw := printf "%v" . -}}
|
||||
{{- $trimmed := strings.TrimSpace $raw -}}
|
||||
{{- $result := dict
|
||||
"isURL" false
|
||||
"label" ""
|
||||
"url" ""
|
||||
-}}
|
||||
{{- if gt (len (findRE `(?i)^https?://[^[:space:]]+$` $trimmed)) 0 -}}
|
||||
{{- $parsedURL := urls.Parse $trimmed -}}
|
||||
{{- $host := replaceRE `:\d+$` "" $parsedURL.Host -}}
|
||||
{{- if ne $host "" -}}
|
||||
{{- $result = dict
|
||||
"isURL" true
|
||||
"label" $host
|
||||
"url" $trimmed
|
||||
-}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- return $result -}}
|
||||
32
layouts/partials/media/process-image.html
Normal file
32
layouts/partials/media/process-image.html
Normal file
@@ -0,0 +1,32 @@
|
||||
{{/* Préserve les GIF animés en évitant toute transformation Hugo. */}}
|
||||
{{- $image := .image -}}
|
||||
{{- if not $image -}}
|
||||
{{- errorf "media/process-image.html: missing image resource" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $action := .action -}}
|
||||
{{- if not $action -}}
|
||||
{{- errorf "media/process-image.html: missing image action for %q" $image.Name -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $spec := .spec -}}
|
||||
{{- if not $spec -}}
|
||||
{{- errorf "media/process-image.html: missing image spec for %q" $image.Name -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $result := $image -}}
|
||||
{{- $subType := lower $image.MediaType.SubType -}}
|
||||
{{- if and (ne $subType "svg") (ne $subType "gif") -}}
|
||||
{{- $options := printf "%s webp q80" $spec -}}
|
||||
{{- if eq $action "Fill" -}}
|
||||
{{- $result = $image.Fill $options -}}
|
||||
{{- else if eq $action "Crop" -}}
|
||||
{{- $result = $image.Crop $options -}}
|
||||
{{- else if eq $action "Resize" -}}
|
||||
{{- $result = $image.Resize $options -}}
|
||||
{{- else -}}
|
||||
{{- errorf "media/process-image.html: unsupported image action %q for %q" $action $image.Name -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- return $result -}}
|
||||
Reference in New Issue
Block a user