Different images URLs between blog and RSS?

Hello!

I wonder if it’s possible to have different URLs for my blog images in the RSS feed.

Example: in the blog, the URL is relative: “images/icon.png”. But in the atom xml file I’d like it to be absolute (because I’d like to use another images source folder for the feed): “http://othersub.mydomain.com/blog/images/icon.png”.

My blog uses atom.xml.builder, should I make a loop in there and modify article.body’s contents with a regex? Seems like a dirty hack. So is there a proper way of doing it?

Thanks!

I’d be tempted to override asset_url:

# source/feed.xml.builder frontmatter

absolute: yes
# data/deployment.yml

url: 'https://www.example.com/'
# helpers/content_helpers.rb

require 'uri'

module ContentHelpers
  def absolute(url)
    URI.join(data.deployment.url, url).to_s
  end

  def asset_url(*args)
    current_page.data.absolute ? absolute(super) : super
  end
end
1 Like