Sha256: 4af69afc941a2f6e2137698fe69f39a397f9264d8f6fc54785fc4584321167fb

Contents?: true

Size: 980 Bytes

Versions: 5

Compression:

Stored size: 980 Bytes

Contents

module Jekyll
  module Tags
    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.slug == @post.slug \
            and p.date.year == @post.date.year \
            and p.date.month == @post.date.month \
            and p.date.day == @post.date.day

            return p.url
          end
        end

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

        return "#"
      end
    end
  end
end

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
jekyll-1.0.0.rc1 lib/jekyll/tags/post_url.rb
jekyll-1.0.0.beta4 lib/jekyll/tags/post_url.rb
jekyll-1.0.0.beta3 lib/jekyll/tags/post_url.rb
jekyll-1.0.0.beta2 lib/jekyll/tags/post_url.rb
jekyll-1.0.0.beta1 lib/jekyll/tags/post_url.rb