From 02e53fb6ff5d668057542b55e71775d1102cbfbf Mon Sep 17 00:00:00 2001 From: Alfred Xing Date: Mon, 27 Oct 2014 22:59:15 -0700 Subject: [PATCH] Implement @parkr's suggestions --- lib/jekyll/url.rb | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/jekyll/url.rb b/lib/jekyll/url.rb index 7dd8cfe7..5adf2468 100644 --- a/lib/jekyll/url.rb +++ b/lib/jekyll/url.rb @@ -37,15 +37,29 @@ module Jekyll # # Returns the String URL def to_s - sanitize_url(generate_url) + sanitize_url(generated_permalink || generated_url) + end + + # Generates a URL from the permalink + # + # Returns the _unsanitized String URL + def generated_permalink + (@generated_permlink ||= generate_url(@permalink)) if @permalink + end + + # Generates a URL from the template + # + # Returns the _unsanitized String URL + def generated_url + @generated_url ||= generate_url(@template) end # Internal: Generate the URL by replacing all placeholders with their - # respective values in the template or permalink + # respective values in the given template # # Returns the _unsanitizied_ String URL - def generate_url - @placeholders.inject(@permalink || @template) do |result, token| + def generate_url(template) + @placeholders.inject(template) do |result, token| break result if result.index(':').nil? result.gsub(/:#{token.first}/, self.class.escape_path(token.last)) end