Finally a nice solution for mapping relative urls

This commit is contained in:
Brandon Mathis 2011-07-21 23:50:32 -04:00
parent 44e1351fc7
commit 39d56bc988
13 changed files with 38 additions and 29 deletions

View file

@ -130,7 +130,7 @@ module Jekyll
#
def category_links(categories)
dir = @context.registers[:site].config['category_dir']
root_url = @context.registers[:site].config['root']
root_url = @context.registers[:site].config['root'].sub(/\/$/, '')
categories = categories.sort!.map do |item|
"<a class='category' href='#{root_url}/#{dir}/#{item.gsub(/_|\W/, '-')}/'>#{item}</a>"
end

View file

@ -20,15 +20,23 @@ module OctopressFilters
end
# Replaces relative urls with full urls
def full_urls(input, url='')
url ||= ''
def expand_urls(input, url='')
url ||= '/'
input.gsub /(\s+(href|src)\s*=\s*["|']{1})(\/[^\"'>]+)/ do
$1+url+$3
end
end
# Returns a url without the http:// for use in as a search modifier eg. 'search terms site:website.com'
def search_url(input)
# Removes trailing forward slash from a string for easily appending url segments
def strip_slash(input)
if input =~ /(.+)\/$|^\/$/
input = $1
end
input
end
# Returns a url without the protocol (http://)
def shorthand_url(input)
input.gsub /(https?:\/\/)(\S+)/ do
$2
end