class Jekyll::FileExistsTag

This class adds a tag that checks if a file exists.

Public Instance Methods

render(context) click to toggle source

Render the tag Params:

context

The context of the page

# File _plugins/file_exists.rb, line 14
def render(context)
  # Pipe parameter through Liquid to make additional replacements possible
  url = Liquid::Template.parse(@path).render context

  # Adds the site source, so that it also works with a custom one
  site_source = context.registers[:site].config['source']
  file_path = "#{site_source}/#{url}"

  # Check if file exists (returns true or false)
  File.exist?(file_path.strip!).to_s
end