From 8b6e69a02565a5552c9e06abfbda08f637cd40c2 Mon Sep 17 00:00:00 2001 From: Richard Dern Date: Mon, 23 Mar 2026 23:24:13 +0100 Subject: [PATCH] Affiche le domaine des attributions URL --- .../layouts/_partials/article-header.html | 3 ++- .../_partials/media/parse-attribution.html | 19 +++++++++++++++++++ .../layouts/_partials/media/render-image.html | 3 ++- themes/2026/layouts/_shortcodes/extimage.html | 3 ++- themes/2026/layouts/_shortcodes/sound.html | 5 ++++- themes/2026/layouts/_shortcodes/video.html | 3 ++- 6 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 themes/2026/layouts/_partials/media/parse-attribution.html diff --git a/themes/2026/layouts/_partials/article-header.html b/themes/2026/layouts/_partials/article-header.html index f0f7cbd8..ee63953c 100644 --- a/themes/2026/layouts/_partials/article-header.html +++ b/themes/2026/layouts/_partials/article-header.html @@ -199,7 +199,8 @@

{{ . | markdownify }}

{{- end -}} {{- with $coverAttribution -}} -

Attribution: {{ . | markdownify }}

+ {{- $attribution := partial "media/parse-attribution.html" . -}} +

Attribution: {{- if index $attribution "isURL" -}}{{ index $attribution "label" }}{{- else -}}{{ . | markdownify }}{{- end -}}

{{- end -}} {{- with $coverPrompt -}}
diff --git a/themes/2026/layouts/_partials/media/parse-attribution.html b/themes/2026/layouts/_partials/media/parse-attribution.html new file mode 100644 index 00000000..31c6d237 --- /dev/null +++ b/themes/2026/layouts/_partials/media/parse-attribution.html @@ -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 -}} diff --git a/themes/2026/layouts/_partials/media/render-image.html b/themes/2026/layouts/_partials/media/render-image.html index c656f7c5..7f3ff9d0 100644 --- a/themes/2026/layouts/_partials/media/render-image.html +++ b/themes/2026/layouts/_partials/media/render-image.html @@ -90,7 +90,8 @@ {{- if or $data.attribution $data.prompt -}}
{{- with $data.attribution -}} -

Attribution : {{ . | markdownify }}

+ {{- $attribution := partial "media/parse-attribution.html" . -}} +

Attribution : {{- if index $attribution "isURL" -}}{{ index $attribution "label" }}{{- else -}}{{ . | markdownify }}{{- end -}}

{{- end -}} {{- with $data.prompt -}}
diff --git a/themes/2026/layouts/_shortcodes/extimage.html b/themes/2026/layouts/_shortcodes/extimage.html index 9d9ff913..b7603098 100644 --- a/themes/2026/layouts/_shortcodes/extimage.html +++ b/themes/2026/layouts/_shortcodes/extimage.html @@ -30,8 +30,9 @@ {{- end -}}
{{- with $attribution -}} + {{- $figureAttribution := partial "media/parse-attribution.html" . -}}
-

Attribution : {{ . | markdownify }}

+

Attribution : {{- if index $figureAttribution "isURL" -}}{{ index $figureAttribution "label" }}{{- else -}}{{ . | markdownify }}{{- end -}}

{{- end -}} diff --git a/themes/2026/layouts/_shortcodes/sound.html b/themes/2026/layouts/_shortcodes/sound.html index 3dc85dd2..6717001f 100644 --- a/themes/2026/layouts/_shortcodes/sound.html +++ b/themes/2026/layouts/_shortcodes/sound.html @@ -13,7 +13,10 @@
{{- with $data.title -}}

{{ . }}

{{- end -}} {{- with $data.description -}}

{{ . | markdownify }}

{{- end -}} - {{- with $data.attribution -}}

Attribution : {{ . | markdownify }}

{{- end -}} + {{- with $data.attribution -}} + {{- $attribution := partial "media/parse-attribution.html" . -}} +

Attribution : {{- if index $attribution "isURL" -}}{{ index $attribution "label" }}{{- else -}}{{ . | markdownify }}{{- end -}}

+ {{- end -}}
{{- end -}} diff --git a/themes/2026/layouts/_shortcodes/video.html b/themes/2026/layouts/_shortcodes/video.html index b75e6c5e..4e2e7e4c 100644 --- a/themes/2026/layouts/_shortcodes/video.html +++ b/themes/2026/layouts/_shortcodes/video.html @@ -23,7 +23,8 @@ {{- if or $data.attribution $data.prompt -}}
{{- with $data.attribution -}} -

Attribution : {{ . | markdownify }}

+ {{- $attribution := partial "media/parse-attribution.html" . -}} +

Attribution : {{- if index $attribution "isURL" -}}{{ index $attribution "label" }}{{- else -}}{{ . | markdownify }}{{- end -}}

{{- end -}} {{- with $data.prompt -}}