Class: Jekyll::J1SeoTag

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

Instance Method Summary collapse

Instance Method Details

#generate(site) ⇒ Object

Main plugin action, called by Jekyll-core



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
# File 'lib/starter_web/_plugins/seo/j1-seo-tags.rb', line 28

def generate(site)
  @site = site

  @mode                             = site.config['environment']
  @template                         = site.config['theme']

  # Resolve config paths relative to the Jekyll source directory.
  # The original `File.dirname(__FILE__).sub('_plugins/seo', '')`
  # was a no-op (the segment '_plugins/seo' never appears in
  # __FILE__), which left @project_path pointing at _plugins
  # instead of the site root. `site.source` is authoritative.
  #
  @project_path                     = site.source
  @module_data_path                 = File.join(@project_path, '_data')
  @module_config_path               = File.join(@module_data_path, 'plugins')
  @module_template_path             = File.join(@module_data_path, 'templates')

  # Safely load default + user settings. Replaces the original
  # `YAML::load(File.open(...))` calls which leaked file handles,
  # used the unsafe loader, and crashed on a missing file.
  #
  default_yaml                      = load_yaml(File.join(@module_config_path, 'defaults', 'seo-tags.yml'))
  user_yaml                         = load_yaml(File.join(@module_config_path, 'seo-tags.yml'))

  @module_config_default_settings   = default_yaml['defaults'] || {}
  @module_config_user_settings      = user_yaml['settings']    || {}

  # Non-destructive merge: user settings override defaults without
  # mutating the loaded defaults hash (the original used `merge!`).
  #
  @module_config                    = @module_config_default_settings.merge(@module_config_user_settings)

  if plugin_disabled?
    Jekyll.logger.info "J1 SEO Tags:", "disabled"
    return
  else
    Jekyll.logger.info "J1 SEO Tags:", "enabled"
    Jekyll.logger.info "J1 SEO Tags:", "generate seo tags"
  end

end