ruby - Including external files in a Jekyll template -
is possible include html file domain within jekyll template? , if syntax be?
i'm not ruby or jekyll developer, more or less asking on behalf of please forgive me if reply obvious! @ to the lowest degree couldn't quite find reply initial research.
in essence we're trying pull markup of footer domain, how production work we're trying simulate in our template deliverables.
cheers
you cannot within template itself. however, define custom liquid tag scrapes markup of remote page, , set tag template. in file called e.g. plugins/remote_footer.rb
require 'nokogiri' require 'open-uri' require 'uri' module jekyll class remotefootertag < liquid::tag def initialize(tag_name, markup, tokens) #markup defined in tag. lets create url devs #don't have update code if url changes. url = markup #check if url valid if url =~ uri::regexp #grab remote document nokogiri doc = nokogiri::html(open(url)) #search document html element want @node = doc.at_xpath("//div[@id='footer']") else raise 'invalid url passed remotefootertag' end super end def render(context) output = super if @node node.to_s else "something went wrong in remotefootertag" end end end end liquid::template.register_tag('remote_footer', jekyll::remotefootertag) and in template:
{% remote_footer http://google.com %} i threw , didn't check if runs, it's plenty work with. maintain in mind run 1 time when liquid parser runs on page, , if remote element changes not reflected until jekyll site rebuilt.
ruby jekyll jekyll-extensions
No comments:
Post a Comment