From e22b1bb74a79732ed8a129b501411a91feee578c Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 11 May 2013 17:40:00 +0200 Subject: [PATCH 01/11] Add deprecation support for pages in subfolders with relative permalinks. --- lib/jekyll/configuration.rb | 5 ++++- lib/jekyll/page.rb | 4 ++++ lib/jekyll/site.rb | 11 +++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index d6856bb1..c76dde9e 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -19,7 +19,10 @@ module Jekyll 'limit_posts' => 0, 'lsi' => false, 'future' => true, # remove and make true just default - 'pygments' => true, # remove and make true just default + 'pygments' => true, + + 'relative_permalinks' => true, # backwards-compatibility with < 1.0 + # will be set to false once 1.1 hits 'markdown' => 'maruku', 'permalink' => 'date', diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index 730af13f..e44cf329 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -144,5 +144,9 @@ module Jekyll def index? basename == 'index' end + + def uses_relative_permalinks + permalink && !permalink.include?(File.expand_path(@dir, site.source)) + end end end diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index d8a36e1b..3264cfc5 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -231,6 +231,7 @@ module Jekyll end self.pages.each do |page| + relative_permalinks_deprecation_method if page.uses_relative_permalinks page.render(self.layouts, payload) end @@ -418,5 +419,15 @@ module Jekyll post.categories.each { |c| self.categories[c] << post } post.tags.each { |c| self.tags[c] << post } end + + def relative_permalinks_deprecation_method + if config['relative_permalinks'] && !@deprecated_relative_permalinks + Jekyll::Logger.warn "Deprecation:", "Starting in 1.1, permalinks for pages" + + " in subfolders must be absolute" + + " permalinks relative to the site" + + " source." + @deprecated_relative_permalinks = true + end + end end end From b355ef646924830ab465fc3f29c9d8c2e7120a06 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 11 May 2013 17:49:20 +0200 Subject: [PATCH 02/11] Add jekyll doctor command --- bin/jekyll | 14 ++++++++++++++ lib/jekyll/page.rb | 9 ++++++++- lib/jekyll/site.rb | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/bin/jekyll b/bin/jekyll index 6d3767e6..2e631bbb 100755 --- a/bin/jekyll +++ b/bin/jekyll @@ -86,6 +86,20 @@ command :serve do |c| end alias_command :server, :serve +command :doctor do |c| + c.syntax = 'jekyll doctor' + c.description = 'Search site and print specific deprecation warnings' + + c.option '--config CONFIG_FILE[,CONFIG_FILE2,...]', Array, 'Custom configuration file' + + c.action do |args, options| + options = normalize_options(options.__hash__) + options = Jekyll.configuration(options) + Jekyll::Commands::Doctor.process(options) + end +end +alias_command :hyde, :doctor + command :import do |c| c.syntax = 'jekyll import [options]' c.description = 'Import your old blog to Jekyll' diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index e44cf329..872c6cce 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -114,7 +114,14 @@ module Jekyll self.data.deep_merge({ "url" => self.url, "content" => self.content, - "path" => self.data['path'] || File.join(@dir, @name).sub(/\A\//, '') }) + "path" => self.data['path'] || path }) + end + + # The path to the source file + # + # Returns the path to the source file + def path + File.join(@dir, @name).sub(/\A\//, '') end # Obtain destination path. diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 3264cfc5..69c4815f 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -422,6 +422,7 @@ module Jekyll def relative_permalinks_deprecation_method if config['relative_permalinks'] && !@deprecated_relative_permalinks + puts # Places newline after "Generating..." Jekyll::Logger.warn "Deprecation:", "Starting in 1.1, permalinks for pages" + " in subfolders must be absolute" + " permalinks relative to the site" + From 6294c4a2049ed2552b29fbdc93e8eb7826c226e7 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 11 May 2013 17:56:42 +0200 Subject: [PATCH 03/11] Better-formatted output with relation to 'Generating... done.' --- lib/jekyll/site.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 69c4815f..549cf098 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -422,11 +422,12 @@ module Jekyll def relative_permalinks_deprecation_method if config['relative_permalinks'] && !@deprecated_relative_permalinks - puts # Places newline after "Generating..." + $stderr.puts # Places newline after "Generating..." Jekyll::Logger.warn "Deprecation:", "Starting in 1.1, permalinks for pages" + " in subfolders must be absolute" + " permalinks relative to the site" + " source." + $stderr.print Jekyll::Logger.formatted_topic("") + "..." # for "done." @deprecated_relative_permalinks = true end end From 19bc54bb079f0abec8048ec606c6ff276cbc1106 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 11 May 2013 18:02:53 +0200 Subject: [PATCH 04/11] Add doctor command --- lib/jekyll/commands/doctor.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 lib/jekyll/commands/doctor.rb diff --git a/lib/jekyll/commands/doctor.rb b/lib/jekyll/commands/doctor.rb new file mode 100644 index 00000000..8338879d --- /dev/null +++ b/lib/jekyll/commands/doctor.rb @@ -0,0 +1,24 @@ +module Jekyll + module Commands + class Doctor < Command + class << self + def process(options) + site = Jekyll::Site.new(options) + site.read + + deprecate_relative_permalinks(site) + end + + def deprecate_relative_permalinks(site) + site.pages.each do |page| + if page.uses_relative_permalinks + Jekyll::Logger.warn "Deprecation:", "'#{page.path}' uses relative" + + " permalinks which will be automatically" + + " deprecated in Jekyll v1.1." + end + end + end + end + end + end +end From 1f23bc4dc01a7ed88b75ae0204a1ed06bf2cd32d Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 11 May 2013 18:03:03 +0200 Subject: [PATCH 05/11] Add support for relative permalinks --- lib/jekyll/page.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index 872c6cce..68eaacc0 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -64,7 +64,11 @@ module Jekyll return @url if @url url = if permalink - permalink + if uses_relative_permalinks + File.join(@dir, permalink) + else + permalink + end else { "path" => @dir, From 161244fd7855da832bb671b083addb76d957f488 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 11 May 2013 18:06:26 +0200 Subject: [PATCH 06/11] Add better language and link to Upgrading page in docs for relative permalinks deprecation msg --- lib/jekyll/site.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 549cf098..16ccd7e9 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -424,9 +424,10 @@ module Jekyll if config['relative_permalinks'] && !@deprecated_relative_permalinks $stderr.puts # Places newline after "Generating..." Jekyll::Logger.warn "Deprecation:", "Starting in 1.1, permalinks for pages" + - " in subfolders must be absolute" + - " permalinks relative to the site" + - " source." + " in subfolders must be relative to the" + + " site source directory, not the parent" + + " directory. Check http://jekyllrb.com/docs/upgrading/"+ + " for more info." $stderr.print Jekyll::Logger.formatted_topic("") + "..." # for "done." @deprecated_relative_permalinks = true end From 0e82b4eb2f49873be0e84e8deaf10eaee813733b Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 11 May 2013 18:26:20 +0200 Subject: [PATCH 07/11] Use site config to determine whether permalinks should be relative. --- lib/jekyll/page.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index 68eaacc0..58da1b83 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -64,7 +64,7 @@ module Jekyll return @url if @url url = if permalink - if uses_relative_permalinks + if site.config['relative_permalinks'] File.join(@dir, permalink) else permalink From 6167747440a7083d7e26b9c462e1f97197b13d9a Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 12 May 2013 01:07:58 +0200 Subject: [PATCH 08/11] Say happy things when everything is cool --- lib/jekyll/commands/doctor.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/commands/doctor.rb b/lib/jekyll/commands/doctor.rb index 8338879d..5ac2a68d 100644 --- a/lib/jekyll/commands/doctor.rb +++ b/lib/jekyll/commands/doctor.rb @@ -6,17 +6,22 @@ module Jekyll site = Jekyll::Site.new(options) site.read - deprecate_relative_permalinks(site) + unless deprecated_relative_permalinks(site) + Jekyll::Logger.info "Your test results", "are in. Everything looks fine." + end end - def deprecate_relative_permalinks(site) + def deprecated_relative_permalinks(site) + contains_deprecated_pages = false site.pages.each do |page| if page.uses_relative_permalinks Jekyll::Logger.warn "Deprecation:", "'#{page.path}' uses relative" + " permalinks which will be automatically" + " deprecated in Jekyll v1.1." + contains_deprecated_pages = true end end + contains_deprecated_pages end end end From 2e1316ec8b96215bc1cd0da4afd4e8757e981472 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 12 May 2013 01:08:33 +0200 Subject: [PATCH 09/11] Ensure the page is in a subdir. That's the only time it's eff'd. --- lib/jekyll/page.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index 58da1b83..1a46c854 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -157,7 +157,7 @@ module Jekyll end def uses_relative_permalinks - permalink && !permalink.include?(File.expand_path(@dir, site.source)) + permalink && @dir != "" && !permalink.include?(File.expand_path(@dir, site.source)) end end end From d9f0dce67d518327d231e6d0ac2879fdba156270 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 12 May 2013 01:16:52 +0200 Subject: [PATCH 10/11] make sure relative_permalinks is set to TRUE --- lib/jekyll/page.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index 1a46c854..ef7c4d3a 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -157,7 +157,7 @@ module Jekyll end def uses_relative_permalinks - permalink && @dir != "" && !permalink.include?(File.expand_path(@dir, site.source)) + permalink && @dir != "" && site.config['relative_permalinks'] end end end From c59cfcfd2e6a88ab22f86f7ec92a89c3bfeebd51 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 12 May 2013 01:19:04 +0200 Subject: [PATCH 11/11] Not automatically deprecated. --- lib/jekyll/commands/doctor.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/commands/doctor.rb b/lib/jekyll/commands/doctor.rb index 5ac2a68d..1819e0c7 100644 --- a/lib/jekyll/commands/doctor.rb +++ b/lib/jekyll/commands/doctor.rb @@ -16,8 +16,8 @@ module Jekyll site.pages.each do |page| if page.uses_relative_permalinks Jekyll::Logger.warn "Deprecation:", "'#{page.path}' uses relative" + - " permalinks which will be automatically" + - " deprecated in Jekyll v1.1." + " permalinks which will be deprecated in" + + " Jekyll v1.1 and beyond." contains_deprecated_pages = true end end