lib/jekyll-linkpreview.rb in jekyll-linkpreview-0.4.1 vs lib/jekyll-linkpreview.rb in jekyll-linkpreview-0.5.0

- old
+ new

@@ -145,11 +145,11 @@ end def render(context) url = get_url_from(context) properties = get_properties(url) - render_linkpreview properties + render_linkpreview context, properties end def get_properties(url) cache_filepath = "#{@@cache_dir}/%s.json" % Digest::MD5.hexdigest(url) if File.exist?(cache_filepath) then @@ -206,22 +206,28 @@ end factory.from_hash(hash) end private - def render_linkpreview(properties) - template_path = get_custom_template_path properties + def render_linkpreview(context, properties) + template_path = get_custom_template_path context, properties if File.exist?(template_path) hash = properties.to_hash_for_custom_template gen_custom_template template_path, hash else gen_default_template properties.to_hash end end private - def get_custom_template_path(properties) - File.join Dir.pwd, @@template_dir, properties.template_file + def get_custom_template_path(context, properties) + source_dir = get_source_dir_from context + File.join source_dir, @@template_dir, properties.template_file + end + + private + def get_source_dir_from(context) + File.absolute_path context.registers[:site].config['source'], Dir.pwd end private def gen_default_template(hash) title = hash['title']