class Jekyll::GitHubMetadata::SiteGitHubMunger

Public Class Methods

new(site) click to toggle source
# File lib/jekyll-github-metadata/site_github_munger.rb, line 12
def initialize(site)
  Jekyll::GitHubMetadata.site = site
end

Public Instance Methods

munge!() click to toggle source
# File lib/jekyll-github-metadata/site_github_munger.rb, line 16
def munge!
  Jekyll::GitHubMetadata.log :debug, "Initializing..."

  # This is the good stuff.
  site.config["github"] = github_namespace

  add_title_and_description_fallbacks!
  add_url_and_baseurl_fallbacks! if should_add_url_fallbacks?
end

Private Instance Methods

add_title_and_description_fallbacks!() click to toggle source
# File lib/jekyll-github-metadata/site_github_munger.rb, line 51
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 { |_c, r| r.name })
  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 44
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 39
def drop
  @drop ||= MetadataDrop.new(GitHubMetadata.site)
end
github_namespace() click to toggle source
# File lib/jekyll-github-metadata/site_github_munger.rb, line 28
def github_namespace
  case site.config["github"]
  when nil
    drop
  when Hash
    Jekyll::Utils.deep_merge_hashes(drop, site.config["github"])
  else
    site.config["github"]
  end
end
should_add_url_fallbacks?() click to toggle source
# File lib/jekyll-github-metadata/site_github_munger.rb, line 69
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 65
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 73
def should_warn_about_site_name?
  site.config["name"] && !site.config["title"]
end