<commit_before>require 'middleman-core'

module Middleman
  class SitemapPing < Extension
    SERVICES = {
      google: 'http://www.google.com/webmasters/tools/ping?sitemap=%SITEMAP_URL%',
      bing:   'http://www.bing.com/ping?sitemap=%SITEMAP_URL%'
    }

    SERVICES.each_key do |service|
      option "ping_#{service}".to_sym, true, "Ping #{service.capitalize}?"
    end
    option :after_build,  true,          'Execute automatically after the site was built?'
    option :host,         nil,           'The host of your website'
    option :sitemap_file, 'sitemap.xml', 'The name of your sitemap file'

    def initialize(app, options_hash = {})
      super

      require 'open-uri'
    end

    def after_build(builder)
      if options.after_build
        self.do_ping builder
      end
    end

    def do_ping(builder)
      raise 'Please set the `host` option for the sitemap ping extension!' unless host = options.host
      host = "http://#{host}" unless host =~ %r(\Ahttps?://)
      sitemap_url = File.join(host, options.sitemap_file)
      SERVICES.each do |service, url|<commit_msg>require open-uri where necessary<commit_after>require 'middleman-core'

module Middleman
  class SitemapPing < Extension
    SERVICES = {
      google: 'http://www.google.com/webmasters/tools/ping?sitemap=%SITEMAP_URL%',
      bing:   'http://www.bing.com/ping?sitemap=%SITEMAP_URL%'
    }

    SERVICES.each_key do |service|
      option "ping_#{service}".to_sym, true, "Ping #{service.capitalize}?"
    end
    option :after_build,  true,          'Execute automatically after the site was built?'
    option :host,         nil,           'The host of your website'
    option :sitemap_file, 'sitemap.xml', 'The name of your sitemap file'

    def initialize(app, options_hash = {})
      super

      require 'open-uri'
    end

    def after_build(builder)
      if options.after_build
        self.do_ping builder
      end
    end

    def do_ping(builder)
      raise 'Please set the `host` option for the sitemap ping extension!' unless host = options.host
      require 'open-uri'
      host = "http://#{host}" unless host =~ %r(\Ahttps?://)
      sitemap_url = File.join(host, options.sitemap_file)
      SERVICES.each do |service, url|
{'fraction_non_alphanumeric': 0.11476868327402136, 'fraction_numerical': 0.0, 'mean_word_length': 2.7989864864864864, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3490846', 'n_tokens_mistral': 738, 'n_tokens_neox': 720, 'n_words': 186}