Created
December 9, 2009 21:43
-
-
Save mattstevens/252850 to your computer and use it in GitHub Desktop.
Webby helper to convert links to absolute URLs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
subtitle: | |
author: Your Name | |
email: [email protected] | |
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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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