From d8af0e0d6c89afc4cc79982cb73a8c094cf5ee5e Mon Sep 17 00:00:00 2001 From: Makise Von Date: Tue, 30 Nov 2021 00:21:57 +0800 Subject: feat: ignore suffix slash of image host (#358) --- layouts/partials/utils/content.html | 4 ++-- layouts/partials/utils/images.html | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/layouts/partials/utils/content.html b/layouts/partials/utils/content.html index a1bf70b..05ec4c4 100644 --- a/layouts/partials/utils/content.html +++ b/layouts/partials/utils/content.html @@ -113,14 +113,14 @@ {{- if and .Site.Params.enableImageHost (eq hugo.Environment "production") -}} - {{- $hostURL := .Site.Params.imageHostURL -}} + {{- $hostURL := strings.TrimSuffix "/" .Site.Params.imageHostURL -}} {{- $temps := findRE `<(img) src="/?([^":]+)` $Content | uniq -}} {{- with $temps -}} {{- range . -}} {{- if not (in (slice "http" "ttps") (substr . -1 4)) -}} {{- $url := replaceRE `<(img) src="/?([^":]+)` `$2` . -}} {{- $prefix := replaceRE `(<(img) src=")/?([^":]+)` `$1` . -}} - {{- $replacement := (printf `%s%s%s` $prefix $hostURL $url) -}} + {{- $replacement := (printf `%s%s/%s` $prefix $hostURL $url) -}} {{- $Content = replace $Content . $replacement -}} {{- end -}} {{- end -}} diff --git a/layouts/partials/utils/images.html b/layouts/partials/utils/images.html index 5282589..275f46f 100644 --- a/layouts/partials/utils/images.html +++ b/layouts/partials/utils/images.html @@ -12,7 +12,7 @@ {{- if and $.Site.Params.enableImageHost $.Site.Params.headAlso -}} {{- if (eq hugo.Environment "production") -}} {{- if ne (substr . 0 4) "http" -}} - {{- $img = printf `%s%s` $.Site.Params.imageHostURL (strings.TrimPrefix "/" $img) -}} + {{- $img = printf `%s/%s` (strings.TrimSuffix "/" $.Site.Params.imageHostURL) (strings.TrimPrefix "/" $img) -}} {{- end -}} {{- end -}} {{- end -}} -- cgit v1.2.3