Class: Sitemap::PingTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- Sitemap::PingTask
- Defined in:
- lib/sitemap/ping_task.rb
Overview
Rake task for easy manual inclusion into your own Jekyll project.
Instance Attribute Summary collapse
-
#deps ⇒ Object
Other rake tasks on which this task depends.
-
#description ⇒ Object
The description of this task.
-
#engines ⇒ Object
Search engines to ping.
-
#name ⇒ Object
The name of this task.
-
#sitemap_url ⇒ Object
The URL of the sitemap which will be sent to each search engine.
Instance Method Summary collapse
-
#define ⇒ Object
:nodoc:.
-
#initialize(name = :ping) {|_self| ... } ⇒ PingTask
constructor
Default constructor for this task.
-
#try_jekyll_config ⇒ Object
Obtains the baseurl from Jekyll's _config.yml file.
Constructor Details
#initialize(name = :ping) {|_self| ... } ⇒ PingTask
Default constructor for this task. See the README.md
for usage
instructions.
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
#deps ⇒ Object
Other rake tasks on which this task depends.
16 17 18 |
# File 'lib/sitemap/ping_task.rb', line 16 def deps @deps end |
#description ⇒ Object
The description of this task.
22 23 24 |
# File 'lib/sitemap/ping_task.rb', line 22 def description @description end |
#engines ⇒ Object
Search engines to ping.
19 20 21 |
# File 'lib/sitemap/ping_task.rb', line 19 def engines @engines end |
#name ⇒ Object
The name of this task.
13 14 15 |
# File 'lib/sitemap/ping_task.rb', line 13 def name @name end |
#sitemap_url ⇒ Object
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
#define ⇒ Object
: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_config ⇒ Object
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 |