Sha256: 419db543e43ed0e248c8a67c6572ad335ea3d590e773ee3d8b310923d77423d9

Contents?: true

Size: 744 Bytes

Versions: 3

Compression:

Stored size: 744 Bytes

Contents

module Jekyll

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

    attr_accessor :date, :slug

    def initialize(name)
      _, 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

3 entries across 3 versions & 1 rubygems

Version Path
jekyll-reloaded-0.12.2 lib/jekyll/tags/post_url.rb
jekyll-reloaded-0.12.1 lib/jekyll/tags/post_url.rb
jekyll-reloaded-0.12 lib/jekyll/tags/post_url.rb