added include_remote tag 🍺
This commit is contained in:
@@ -18,13 +18,13 @@
|
||||
<link href="{{ site.shared_baseurl }}/css/docs.min.css" rel="stylesheet">
|
||||
<link href="//fast.fonts.net/cssapi/e6dc9b99-64fe-4292-ad98-6974f93cd2a2.css" rel="stylesheet">
|
||||
<link href="//afeld.github.io/emoji-css/emoji.css" rel="stylesheet">
|
||||
{% include favicons.html %}
|
||||
{% include_remote {{ site.shared_baseurl }}/_docs/favicons.html %}
|
||||
</head>
|
||||
<body role="document" data-shared-baseurl="{{ site.shared_baseurl }}" data-baseurl="{{ site.baseurl }}">
|
||||
{% if page.url contains '/demo/' %}
|
||||
{% include menu_demo.html %}
|
||||
{% include_remote {{ site.shared_baseurl }}/_docs/menu_demo.html %}
|
||||
{% else %}
|
||||
{% include menu.html %}
|
||||
{% include_remote {{ site.shared_baseurl }}/_docs/menu.html %}
|
||||
{% endif %}
|
||||
|
||||
<div class="top-bar">
|
||||
@@ -78,7 +78,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% include footer.html %}
|
||||
{% include_remote {{ site.shared_baseurl }}/index.html css="footer" %}
|
||||
<script src="{{ site.shared_baseurl }}/scripts/common.min.js"></script>
|
||||
<script src="{{ site.shared_baseurl }}/scripts/docs.min.js"></script>
|
||||
</body>
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
require 'nokogiri'
|
||||
require 'open-uri'
|
||||
require 'uri'
|
||||
|
||||
class Jekyll::IncludeRemoteTag < Jekyll::Tags::IncludeTag
|
||||
@@remote_cache = {}
|
||||
|
||||
def initialize(tag_name, markup, tokens)
|
||||
super
|
||||
@url = @file
|
||||
end
|
||||
|
||||
def validate_url(url)
|
||||
if url !~ URI::regexp
|
||||
raise ArgumentError.new <<-eos
|
||||
Invalid syntax for include_remote tag. URL contains invalid characters or sequences:
|
||||
|
||||
#{url}
|
||||
|
||||
Valid syntax:
|
||||
|
||||
#{syntax_example}
|
||||
|
||||
eos
|
||||
end
|
||||
end
|
||||
|
||||
def syntax_example
|
||||
"{% #{@tag_name} http://domain.ltd css=\".menu\" xpath=\"//div[@class='.menu']\" param=\"value\" param2=\"value\" %}"
|
||||
end
|
||||
|
||||
def render(context)
|
||||
@url = render_variable(context) || @url
|
||||
validate_url(@url)
|
||||
|
||||
if @params
|
||||
validate_params
|
||||
@params = parse_params(context)
|
||||
end
|
||||
|
||||
xpath = @params['xpath']
|
||||
css = @params['css']
|
||||
|
||||
if ! html = @@remote_cache["#{@url}_#{xpath}"]
|
||||
# fetch remote file
|
||||
page = Nokogiri::HTML(open(@url))
|
||||
|
||||
# parse extract xpath/css fragments if necessary
|
||||
node = page.at_xpath(xpath) if xpath
|
||||
node = page.css(css) if css
|
||||
node = page if !node
|
||||
|
||||
raise IOError.new "Error while parsing remote file '#{@url}': '#{xpath||css}' not found" if !node
|
||||
|
||||
# cache result
|
||||
html = @@remote_cache["#{@url}_#{xpath}"] = node.to_s
|
||||
end
|
||||
|
||||
begin
|
||||
partial = Liquid::Template.parse(html)
|
||||
|
||||
context.stack do
|
||||
context['include'] = @params
|
||||
partial.render!(context)
|
||||
end
|
||||
rescue => e
|
||||
raise Jekyll::Tags::IncludeTagError.new e.message, @url
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Liquid::Template.register_tag('include_remote', Jekyll::IncludeRemoteTag)
|
||||
@@ -14,18 +14,6 @@ else
|
||||
cp _config-local.sample.yml _config-local.yml
|
||||
fi
|
||||
|
||||
echo " > downloading html includes 1/4"
|
||||
curl -s https://www.tinymce.com/_docs/menu.html > _includes/menu.html
|
||||
|
||||
echo " > downloading html includes 2/4"
|
||||
curl -s https://www.tinymce.com/_docs/menu_demo.html > _includes/menu_demo.html
|
||||
|
||||
echo " > downloading html includes 3/4"
|
||||
curl -s https://www.tinymce.com/_docs/footer.html > _includes/footer.html
|
||||
|
||||
echo " > downloading html includes 4/4"
|
||||
curl -s https://www.tinymce.com/_docs/favicons.html > _includes/favicons.html
|
||||
|
||||
echo " > creating dummy API ref data file"
|
||||
echo [] > _data/nav_api.json
|
||||
|
||||
|
||||
Reference in New Issue
Block a user