Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixing config handling.
  • Loading branch information
ianjevans committed Mar 17, 2021
commit 39158c6f1c8a229bf00024568e19fbd509be46b2
13 changes: 10 additions & 3 deletions lib/jekyll-remote-include.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,24 @@ def initialize(tag_name, remote_include, tokens)

# Returns the plugin's config or an empty hash if not set
def config
@config ||= @site.config["remote_include"] || {}
@config ||= @context.registers[:site].config['remote_include'] || {}
end

def open(url)
if config["use_cache"] == true || !config["use_cache"]
if config['use_cache'] == true || !config.has_key?('use_cache')
cache.getset(url) do
Net::HTTP.get(URI.parse(url.strip)).force_encoding 'utf-8'
end
elsif !config["use_cache"]
Net::HTTP.get(URI.parse(url.strip)).force_encoding 'utf-8'
else
@logger.warn("use_cache set to non-boolean value, retrieving remote file just in case.")
Net::HTTP.get(URI.parse(url.strip)).force_encoding 'utf-8'
end
end

def render(context)
@context = context
@logger = Logger.new(STDOUT)
# get the remote URL and see if the string has begin/end tokens
input_split = split_params(@remote_include)
Expand All @@ -54,14 +59,16 @@ def render(context)
@logger.warn("Begin token present? " << begin_match)
@logger.warn("End token: " << end_token)
@logger.warn("End token present? " << end_match)
if config["on_token_error"] == "fail" || !config["on_token_error"]
if config["on_token_error"] == "fail" || !config.has_key?("on_token_error")
# Fail the build by default if there are token errors
raise ArgumentError, "Remote fragment include error in " << context.environments.first["page"]["path"]
elsif config["on_token_error"] == "full"
# if the file doesn't have the begin and end token just output the entire file
output = raw
elsif config["on_token_error"] == "none"
output = ""
else
raise ArgumentError, "on_token_error setting in remote_include configuration invalid"
end
end
else
Expand Down