Skip to content

Commit

Permalink
feat: ignore suffix slash of image host (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
makisevon committed Nov 29, 2021
1 parent adefef8 commit d8af0e0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions layouts/partials/utils/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@

<!-- Image Hosting -->
{{- 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 -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/utils/images.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
Expand Down

0 comments on commit d8af0e0

Please sign in to comment.