Sha256: 387e80f338e922dec873f8721dc9a1eabb7fceb27c2a909e26e4fb32d54c9d0c

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

module Awestruct
  module Extensions
    class Posts

      def initialize(path_prefix)
        @path_prefix = path_prefix
      end

      def execute(site)
        posts = []
    
        site.pages.each do |page|
          if ( page.relative_source_path =~ /^#{@path_prefix}\/(20[01][0-9])-([01][0-9])-([0123][0-9])-(.*)((\.html.haml)|(\.[^.]+))$/ )
            year  = $1
            month = $2
            day   = $3
            slug  = $4
            page.date = Time.utc( year.to_i, month.to_i, day.to_i )
            page.slug = slug
            context = OpenStruct.new({
              :site=>site,
              :page=>page,
            })
            #page.body = page.render( context )
            page.output_path = "#{@path_prefix}/#{year}/#{month}/#{day}/#{slug}.html"
            posts << page
          end
        end
        
        posts = posts.sort_by{|each| [each.date, File.mtime( each.source_path ), each.slug ] }.reverse
        
        last = nil
        posts.each do |e|
          if ( last != nil )
             e.next = last
             last.previous = e
          end
          last = e
        end
        
        site.posts = posts
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
awestruct-0.0.2 lib/awestruct/extensions/posts.rb
awestruct-0.0.1 lib/awestruct/extensions/posts.rb