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/commands/doctor.rb b/lib/jekyll/commands/doctor.rb new file mode 100644 index 00000000..1819e0c7 --- /dev/null +++ b/lib/jekyll/commands/doctor.rb @@ -0,0 +1,29 @@ +module Jekyll + module Commands + class Doctor < Command + class << self + def process(options) + site = Jekyll::Site.new(options) + site.read + + unless deprecated_relative_permalinks(site) + Jekyll::Logger.info "Your test results", "are in. Everything looks fine." + end + end + + 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 deprecated in" + + " Jekyll v1.1 and beyond." + contains_deprecated_pages = true + end + end + contains_deprecated_pages + end + end + end + end +end diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index 50dca537..0db188d3 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..ef7c4d3a 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 site.config['relative_permalinks'] + File.join(@dir, permalink) + else + permalink + end else { "path" => @dir, @@ -114,7 +118,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. @@ -144,5 +155,9 @@ module Jekyll def index? basename == 'index' end + + def uses_relative_permalinks + permalink && @dir != "" && site.config['relative_permalinks'] + end end end diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index d8a36e1b..16ccd7e9 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,18 @@ 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 + $stderr.puts # Places newline after "Generating..." + Jekyll::Logger.warn "Deprecation:", "Starting in 1.1, permalinks for pages" + + " 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 + end end end