Sha256: 24d6bb7ff7edd636ba0f165e9fc95343d68d75f76b64465dcd2bf2b65d6b020f

Contents?: true

Size: 905 Bytes

Versions: 1

Compression:

Stored size: 905 Bytes

Contents

# frozen_string_literal: true

require 'middleman-robots/generator'
require 'tempfile'

module Middleman
  module Robots
    # Robots Extension Class
    class Extension < ::Middleman::Extension
      option :rules, [], 'List of rules about sitemap.xml'
      option :sitemap, false, 'URI of sitemap.xml'

      def manipulate_resource_list(resources)
        write_robots(options)
        robots = Middleman::Sitemap::Resource.new(
          app.sitemap,
          'robots.txt',
          tmp_path
        )

        logger.info '== middleman-robots: robots.txt added to resources =='
        resources << robots
      end

      def write_robots(options)
        File.open(tmp_path, 'w+') do |f|
          f.puts(Generator.new(options.rules, options.sitemap).process)
        end
      end

      def tmp_path
        File.expand_path('../../tmp/robots/robots.txt', __dir__)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
middleman-robots-1.3.5 lib/middleman-robots/extension.rb