Skip to content

Instantly share code, notes, and snippets.

@mattstevens
Created December 9, 2009 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mattstevens/252850 to your computer and use it in GitHub Desktop.
Save mattstevens/252850 to your computer and use it in GitHub Desktop.
Webby helper to convert links to absolute URLs
module AbsoluteUrlHelper
def abs_url( input, dir )
return input unless SITE.base
return SITE.base + input if input[0,1] == '/'
rgxp = %r/(src|href)="([^"]*)"/
input.gsub!(rgxp) do
path = $2
path = URI.join(SITE.base, "/#{dir}/" ,path)
%Q(#{$1}="#{path}")
end
return input
end
end
Webby::Helpers.register(AbsoluteUrlHelper)
---
subtitle:
author: Your Name
email: you@yourdomain.com
extension: xml
layout: nil
dirty: true
filter: erb
---
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title><%= h(SITE.name) %></title>
<subtitle><%= h(@page.subtitle) %></subtitle>
<link href="<%= SITE.base %>/feed" rel="self" />
<link href="<%= SITE.base %>/" />
<updated><%= Time.now.xmlschema %></updated>
<author>
<name><%= h(@page.author) %></name>
<email><%= h(@page.email) %></email>
</author>
<id><%= SITE.base %>/feed</id>
<% @pages.find(:limit => 10,
:in_directory => 'posts',
:layout => 'post',
:recursive => true,
:sort_by => 'created_at',
:reverse => true).each do |post|
next if post == @page
%>
<entry>
<title><%= h(post.title) %></title>
<link href="<%= SITE.base + post.url %>" />
<id>tag:yourdomain.com,<%= post.created_at.strftime('%Y-%m-%d') %>:<%= post.created_at.to_i %></id>
<updated><%= post.created_at.xmlschema %></updated>
<content type="html"><%= h(abs_url(render(post), post.dir)) %></content>
</entry>
<% end %>
</feed>
# Define the base URL in the sitefile
SITE.base = 'http://yourdomain.com'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment