lib/jekyll/page.rb in jekyll-0.12.1 vs lib/jekyll/page.rb in jekyll-1.0.0.beta1

- old
+ new

@@ -1,7 +1,6 @@ module Jekyll - class Page include Convertible attr_writer :dir attr_accessor :site, :pager @@ -22,10 +21,22 @@ self.process(name) self.read_yaml(File.join(base, dir), name) end + # Read the YAML frontmatter. + # + # base - The String path to the dir containing the file. + # name - The String filename of the file. + # + # Returns nothing. + def read_yaml(base, name) + super(base, name) + self.data['layout'] = 'page' unless self.data.has_key?('layout') + self.data + end + # The generated directory into which the page will be placed # upon generation. This is derived from the permalink or, if # permalink is absent, we be '/' # # Returns the String destination directory. @@ -43,14 +54,20 @@ # The template of the permalink. # # Returns the template String. def template - if self.site.permalink_style == :pretty && !index? && html? - "/:basename/" + if self.site.permalink_style == :pretty + if index? && html? + "/:path/" + elsif html? + "/:path/:basename/" + else + "/:path/:basename:output_ext" + end else - "/:basename:output_ext" + "/:path/:basename:output_ext" end end # The generated relative url of this page. e.g. /about.html. # @@ -60,10 +77,11 @@ url = if permalink permalink else { + "path" => @dir, "basename" => self.basename, "output_ext" => self.output_ext, }.inject(template) { |result, token| result.gsub(/:#{token.first}/, token.last) }.gsub(/\/\//, "/") @@ -103,11 +121,11 @@ # Convert this Page's data to a Hash suitable for use by Liquid. # # Returns the Hash representation of this Page. def to_liquid self.data.deep_merge({ - "url" => File.join(@dir, self.url), + "url" => self.url, "content" => self.content }) end # Obtain destination path. # @@ -115,11 +133,11 @@ # # Returns the destination file path String. def destination(dest) # The url needs to be unescaped in order to preserve the correct # filename. - path = File.join(dest, @dir, CGI.unescape(self.url)) + path = File.join(dest, CGI.unescape(self.url)) path = File.join(path, "index.html") if self.url =~ /\/$/ path end # Write the generated page file to the destination directory. @@ -147,9 +165,7 @@ # Returns the Boolean of whether this Page is an index file or not. def index? basename == 'index' end - end - end