Class: Jekyll::J1Sitemap

Inherits:
Generator
  • Object
show all
Defined in:
lib/starter_web/_plugins/seo/j1-sitemap.rb

Instance Method Summary collapse

Instance Method Details

#generate(site) ⇒ Object

Main plugin action, called by Jekyll-core



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/starter_web/_plugins/seo/j1-sitemap.rb', line 24

def generate(site)
  @site = site

  @mode                             = site.config['environment']
  @template                         = site.config['theme']
  @project_path                     = File.join(File.dirname(__FILE__)).sub('_plugins/seo', '')
  @plugin_data_path                 = File.join(@project_path, site.config['data_dir'])
  @module_config_path               = File.join(@project_path, site.config['data_dir'], 'plugins')

  @module_config_default            = YAML::load(File.open(File.join(@module_config_path, 'defaults', 'sitemap.yml')))
  @module_config_user               = YAML::load(File.open(File.join(@module_config_path, 'sitemap.yml')))

  @module_config_default_settings   = @module_config_default['defaults']
  @module_config_user_settings      = @module_config_user['settings']
  @module_config                    = @module_config_default_settings.merge!(@module_config_user_settings)

  @template_source_folder           = File.join(@project_path, @module_config['template_source_folder'])
  @robots_theme_name             = @module_config['robots_theme_name']
  @sitemap_theme_name            = @module_config['sitemap_theme_name']

  @robots_source_path ||= File.expand_path @robots_theme_name, @template_source_folder
  @sitemap_source_path ||= File.expand_path @sitemap_theme_name, @template_source_folder

  if plugin_disabled?
    Jekyll.logger.info "J1 Sitemap:", "disabled"
    return
  else
    Jekyll.logger.info "J1 Sitemap:", "enabled"
    Jekyll.logger.info "J1 Sitemap:", "generate sitemap files"
  end

  @site.pages << sitemap unless file_exists?("sitemap.xml")
  @site.pages << robots unless file_exists?("robots.txt")
end