class Middleman::SitemapPing::Extension

Constants

SERVICES

Public Instance Methods

after_build(builder) click to toggle source
# File lib/middleman-sitemap-ping/extension.rb, line 18
def after_build(builder)
  if options.after_build
    do_ping builder.thor
  end
end
do_ping(thor) click to toggle source
# File lib/middleman-sitemap-ping/extension.rb, line 24
def do_ping(thor)
  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|
    next unless options.send("ping_#{service}")
    url.sub! /%SITEMAP_URL%\z/, CGI.escape(sitemap_url)
    thor.say "Pinging #{url}"
    open url do |f|
      if f.status[0] == '200'
        thor.say_status :success, 'SUCCESS!', :green
      else
        thor.say_status :error, "ERROR: #{f.status[0]}", :red
      end
    end
  end
end