Convert wordpress links to local links, implement post_link tag that includes baseurl

This commit is contained in:
2015-12-21 15:29:40 +00:00
parent daa43a5728
commit 2c63c50fe3
37 changed files with 159 additions and 39 deletions

31
_plugins/post_link.rb Normal file
View File

@@ -0,0 +1,31 @@
require 'jekyll/tags/post_url'
module Jekyll
class PostLink < Liquid::Tag
def initialize(tag_name, post, tokens)
super
@orig_post = post.strip
begin
@post = Jekyll::Tags::PostComparer.new(@orig_post)
rescue
raise ArgumentError.new <<-eos
Could not parse name of post "#{@orig_post}" in tag 'post_url'.
Make sure the post exists and the name is correct.
eos
end
end
def render(context)
site = context.registers[:site]
site.posts.docs.each do |p|
if @post == p
return '/' + context.registers[:site].config['baseurl'] + p.url
end
end
end
end
end
Liquid::Template.register_tag('post_link', Jekyll::PostLink)