Quantcast
Channel: Page Bundle, relative image path in RSS feed wrong
Viewing all articles
Browse latest Browse all 10

Page Bundle, relative image path in RSS feed wrong

$
0
0

Came here through a search engine. An RSS-specific image render hook is working well for me, thanks @pamubay!

I put the following contents in layouts/_default/_markup/render-image.rss.xml:

{{/* Make sure to always use absolute image URLs in RSS feeds. */}}
{{- $srcUrl := "" -}}
{{- if or (hasPrefix .Destination "http://") (hasPrefix .Destination "https://") -}}
  {{ $srcUrl = .Destination }}
{{- else if hasPrefix .Destination "/" -}}
  {{ $srcUrl = absURL .Destination }}
{{- else -}}
  {{ $imageResource := .Page.Resources.Get .Destination }}
  {{- if $imageResource -}}
    {{ $srcUrl = $imageResource.Permalink }}
  {{- else -}}
    {{ $srcUrl = ref .Page .Destination }}
  {{- end -}}
{{- end -}}
<img src="{{ $srcUrl | safeURL }}" alt="{{ .Text }}" {{ with .Title }}title="{{ . }}"{{ end }}>

This passes absolute URLs with a protocol through as-is, resolves URLs starting with a / relative to the site base URL, and resolves relative URLs as resources in the page bundle before trying them relative to the page URL.

Parts of this are untested and I’m sure there is room for improvement, but this works for me, for now.

Read full topic


Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images