Sha256: ed595777cb44a76d42a6874ffd445bbb942888029d563f34532e1e5aece1d04f

Contents?: true

Size: 751 Bytes

Versions: 6

Compression:

Stored size: 751 Bytes

Contents

module Jekyll

  class PostComparer
    MATCHER = /^(.+\/)*(\d+-\d+-\d+)-(.*)$/

    attr_accessor :date, :slug

    def initialize(name)
      who, cares, date, slug = *name.match(MATCHER)
      @slug = slug
      @date = Time.parse(date)
    end
  end

  class PostUrl < Liquid::Tag
    def initialize(tag_name, post, tokens)
      super
      @orig_post = post.strip
      @post = PostComparer.new(@orig_post)
    end

    def render(context)
      site = context.registers[:site]
      
      site.posts.each do |p|
        if p == @post
          return p.url
        end
      end

      puts "ERROR: post_url: \"#{@orig_post}\" could not be found"

      return "#"
    end
  end
end

Liquid::Template.register_tag('post_url', Jekyll::PostUrl)

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
jekyll-0.12.1 lib/jekyll/tags/post_url.rb
jekyll-0.12.0 lib/jekyll/tags/post_url.rb
spinto-jekyll-0.11.2.5 lib/jekyll/tags/post_url.rb
spinto-jekyll-0.11.2.3 lib/jekyll/tags/post_url.rb
spinto-jekyll-0.11.2.2 lib/jekyll/tags/post_url.rb
spinto-jekyll-0.11.2.1 lib/jekyll/tags/post_url.rb