Class: J1Feed::Generator

Inherits:
Jekyll::Generator
  • Object
show all
Defined in:
lib/starter_web/_plugins/seo/j1-feed.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/starter_web/_plugins/seo/j1-feed.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', 'feed.yml')))
  @module_config_user               = YAML::load(File.open(File.join(@module_config_path, 'feed.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)

  @feed_generation_path             = @module_config['path'].sub('feed.xml', 'for_categories')
  @feed_generation_enabled          = @module_config['enabled']

  @template_source_folder           = File.join(@project_path, @module_config['template_source_folder'])
  @template_name                    = @module_config['template_name']
  @feed_output                      = @module_config['feed_output']

  if disabled_in_development?
    Jekyll.logger.info "J1 Feeds:", "skipped in mode development"
    return
  end

  if plugin_disabled?
    Jekyll.logger.info "J1 Feeds:", "disabled"
    return
  else
    Jekyll.logger.info "J1 Feeds:", "enabled"
  end

  if @module_config['excerpt_only']
    Jekyll.logger.info "J1 Feeds:", "generate rss feeds for: excerpts only"
  end

  if @module_config['posts_limit'] < 100
    Jekyll.logger.info "J1 Feeds:", "generate rss feeds for: #posts of #{@module_config['posts_limit']}"
  else
    Jekyll.logger.info "J1 Feeds:", "generate rss feeds for: #posts of unlimited"
  end

  collections.each do |name, meta|
    Jekyll.logger.info "J1 Feeds:", "generate rss feeds for: all #{name}"
    (meta["categories"] + [nil]).each do |category|
      Jekyll.logger.info "J1 Feeds:", "generate rss feeds for posts by category: #{category}" if category
      path = feed_path(:collection => name, :category => category)

      # rebuild the feed xml file?
      #
      unless @module_config['rebuild_feeds']
        path = feed_path(:collection => name, :category => category)
        if file_exists?(path)
          Jekyll.logger.info "J1 Feeds:", "feed already exist, skip rebuild"
          next
        end
      end

      @site.pages << make_page(path, :collection => name, :category => category)
    end
  end
  generate_feed_by_tag if config['tags'] && !@site.tags.empty?
end