# frozen_string_literal: true require "fileutils" module Jekyll class JekyllRobots < Jekyll::Generator safe true priority :lowest # Main plugin action, called by Jekyll-core def generate(site) @site = site @site.pages << robots end # Path to robots.txt template file def source_path(file = "robots.txt") File.expand_path "../#{file}", __dir__ end # Destination for robots.txt file within the site source directory def destination_path(file = "robots.txt") @site.in_dest_dir(file) end def robots robots = PageWithoutAFile.new(@site, __dir__, "", "robots.txt") robots.data["layout"] = nil robots end # Checks if a file already exists in the site source def file_exists?(file_path) if @site.respond_to?(:in_source_dir) File.exist? @site.in_source_dir(file_path) else File.exist? Jekyll.sanitized_path(@site.source, file_path) end end end end