Auto-prepending links in RSS feeds with your domain (on Radiant)
When you syndicate Radiant content, you may hit the problem of internal links, or img src attributes pointing to invalid paths on a syndicator's domain. So, for example, an aggregator may link to http://aggregator.com/about-us instead of http://your-site.com/about-us. The simple fix is ofcourse to use absolute URLs for all your href and src attributes, but that is not default behavior in Radiant (or most CMSes as far as i know).
If you are using paperclipped, and use <r:asset /> tags to display images, you could fix their src attributes in script console or via the Settings extension by doing:
Radiant::Config["assets.url"] = "http://your-site.com/:class/:id/:basename:no_original_style.:extension"
But that still leaves you with the fact that <r:url />, <r:link /> and some other radius tags output relative urls. Heck, you may even have a few clients that are smart enough to write urls by hand! Here's a method that will convert all relative URLs to absolute ones;
def fix_for_syndication(text, host) text.gsub(/href=('|")([^(http:|mailto:)].*?)('|")/,
'href="' + host + '\2"').gsub(/src=('|")([^http:].*?)('|")/, 'src="' +
host + '\2"') end
From there you can make a simple radius tag to use where-ever you output stuff to an RSS feed;
tag 'fix_links_for_syndication' do |tag| fix_for_syndication(tag.expand,
"#{tag.globals.page.request.protocol}#{tag.globals.page.request.host_with_port}")
end
I used this in one of our own extensions (works-for-us'ish), use at your own risk; probably not compatible with the standard 'blog' extension for example.
In a reading mood?
About this article
You’re reading an entry titled “Auto-prepending links in RSS feeds with your domain (on Radiant)”. Written 6 months ago (11/09/2009) — and archived under absolute-urls, rss. So far, 1 people (dis)agreed with me, what do you think?
About me
I'm Benny Degezelle, a 26 year-old dude from Ghent, Belgium. I'm self employed, being one half of Gorilla webdesign.
I ♥ music, my job, card-playing evenings or party nights with friends and clean code.
Fellow geeks can link up with me on linkedin, ladies and friends may stalk me on Facebook.
What the fuzz is all about
- 2 pages are tagged with WYM
- 1 page is tagged with absolute-urls
- 1 page is tagged with assets
- 2 pages are tagged with documentation
- 2 pages are tagged with editor
- 2 pages are tagged with extension
- 2 pages are tagged with extensions
- 1 page is tagged with page_attachments
- 1 page is tagged with pagination
- 9 pages are tagged with radiant
- 3 pages are tagged with rails
- 2 pages are tagged with ruby
- 2 pages are tagged with shell
- 1 page is tagged with terminal
- 2 pages are tagged with troubleshooting
Github activity
- jomz pushed to master at jomz/radiant-ck_editor_filter-extension
- jomz pushed to master at jomz/radiant-ck_editor_filter-extension
- jomz created branch master at jomz/radiant-ck_editor_filter-extension
- jomz created repository radiant-ck_editor_filter-extension
- jomz forked djcp/radiant-fckeditor
I am in no way responsible for any sillyness going on below this line:
By Tony
On September 22, 2009