Class: Sitemap::PingTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/sitemap/ping_task.rb

Overview

Rake task for easy manual inclusion into your own Jekyll project.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = :ping) {|_self| ... } ⇒ PingTask

Default constructor for this task. See the README.md for usage instructions.

Yields:

  • (_self)

Yield Parameters:


28
29
30
31
32
33
34
35
36
# File 'lib/sitemap/ping_task.rb', line 28

def initialize(name = :ping)
  @name = name
  @engines = [:google, :bing]
  @description = 'Inform search engines of updated sitemap contents'
  @deps = []
  @sitemap_url = try_jekyll_config
  yield self if block_given?
  define
end

Instance Attribute Details

#depsObject

Other rake tasks on which this task depends.


16
17
18
# File 'lib/sitemap/ping_task.rb', line 16

def deps
  @deps
end

#descriptionObject

The description of this task.


22
23
24
# File 'lib/sitemap/ping_task.rb', line 22

def description
  @description
end

#enginesObject

Search engines to ping.


19
20
21
# File 'lib/sitemap/ping_task.rb', line 19

def engines
  @engines
end

#nameObject

The name of this task.


13
14
15
# File 'lib/sitemap/ping_task.rb', line 13

def name
  @name
end

#sitemap_urlObject

The URL of the sitemap which will be sent to each search engine.


25
26
27
# File 'lib/sitemap/ping_task.rb', line 25

def sitemap_url
  @sitemap_url
end

Instance Method Details

#defineObject

:nodoc:


47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/sitemap/ping_task.rb', line 47

def define
  namespace :sitemap do
    desc @description
    task @name => Array(@deps) do
      raise Sitemap::UrlError if @sitemap_url.nil?
      @engines.each do |e|
        result = Sitemap::Ping.ping_sitemap(e, @sitemap_url)
        puts "#{result.message}: #{result.uri}"
      end
    end
  end
end

#try_jekyll_configObject

Obtains the baseurl from Jekyll's _config.yml file.


39
40
41
42
43
44
# File 'lib/sitemap/ping_task.rb', line 39

def try_jekyll_config
  config = YAML.load_file('_config.yml')
  URI.join(config['url'], config['baseurl'], '/sitemap.xml').to_s
rescue SystemCallError
  nil
end