class Jekyll::GitHubMetadata::SiteGitHubMunger

Attributes

global_munger[RW]

Public Class Methods

new(site) click to toggle source
# File lib/jekyll-github-metadata/site_github_munger.rb, line 16
def initialize(site)
  Jekyll::GitHubMetadata.site = site
  @original_config = site.config["github"]
end

Public Instance Methods

inject_metadata!(payload) click to toggle source
# File lib/jekyll-github-metadata/site_github_munger.rb, line 28
def inject_metadata!(payload)
  payload.site["github"] = github_namespace
end
munge!() click to toggle source
# File lib/jekyll-github-metadata/site_github_munger.rb, line 21
def munge!
  Jekyll::GitHubMetadata.log :debug, "Initializing..."

  add_title_and_description_fallbacks!
  add_url_and_baseurl_fallbacks! if should_add_url_fallbacks?
end
uninject_metadata!(payload) click to toggle source
# File lib/jekyll-github-metadata/site_github_munger.rb, line 32
def uninject_metadata!(payload)
  payload.site["github"] = @original_config
end

Private Instance Methods

add_title_and_description_fallbacks!() click to toggle source
# File lib/jekyll-github-metadata/site_github_munger.rb, line 61
def add_title_and_description_fallbacks!
  if should_warn_about_site_name?
    msg =  "site.name is set in _config.yml, but many plugins and themes expect "
    msg << "site.title to be used instead. To avoid potential inconsistency, "
    msg << "Jekyll GitHub Metadata will not set site.title to the repository's name."
    Jekyll::GitHubMetadata.log :warn, msg
  else
    site.config["title"] ||= Value.new("title", proc { |_context, repository|
      if repository.project_page?
        repository.name
      else
        repository.owner_display_name || repository.owner
      end
    })
  end
  site.config["description"] ||= Value.new("description", proc { |_c, r| r.tagline })
end
add_url_and_baseurl_fallbacks!() click to toggle source

Set ‘site.url` and `site.baseurl` if unset.

# File lib/jekyll-github-metadata/site_github_munger.rb, line 54
def add_url_and_baseurl_fallbacks!
  site.config["url"] ||= Value.new("url", proc { |_c, r| r.url_without_path })
  return unless should_set_baseurl?

  site.config["baseurl"] = Value.new("baseurl", proc { |_c, r| r.baseurl })
end
drop() click to toggle source
# File lib/jekyll-github-metadata/site_github_munger.rb, line 49
def drop
  @drop ||= MetadataDrop.new(GitHubMetadata.site)
end
github_namespace() click to toggle source
# File lib/jekyll-github-metadata/site_github_munger.rb, line 38
def github_namespace
  case @original_config
  when nil
    drop
  when Hash
    drop.merge(@original_config)
  else
    @original_config
  end
end
should_add_url_fallbacks?() click to toggle source
# File lib/jekyll-github-metadata/site_github_munger.rb, line 85
def should_add_url_fallbacks?
  Jekyll.env == "production" || Pages.page_build?
end
should_set_baseurl?() click to toggle source

Set the baseurl only if it is ‘nil` or `/` Baseurls should never be “/”. See bit.ly/2s1Srid

# File lib/jekyll-github-metadata/site_github_munger.rb, line 81
def should_set_baseurl?
  site.config["baseurl"].nil? || site.config["baseurl"] == "/"
end
should_warn_about_site_name?() click to toggle source
# File lib/jekyll-github-metadata/site_github_munger.rb, line 89
def should_warn_about_site_name?
  site.config["name"] && !site.config["title"]
end