Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions lib/jekyll-github-metadata/site_github_munger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,31 @@ def add_url_and_baseurl_fallbacks!
site.config["baseurl"] = Value.new("baseurl", proc { |_c, r| r.baseurl })
end

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

# Set the baseurl only if it is `nil` or `/`
# Baseurls should never be "/". See http://bit.ly/2s1Srid
def should_set_baseurl?
site.config["baseurl"].nil? || site.config["baseurl"] == "/"
end

def add_title_and_description_fallbacks!
site.config["title"] ||= Value.new("title", proc { |_c, r| r.name })
site.config["description"] ||= Value.new("description", proc { |_c, r| r.tagline })
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved above to group the bang and should methods together.

def should_add_url_fallbacks?
Jekyll.env == "production" || Pages.page_build?
end

def should_warn_about_site_name?
site.config["name"] && !site.config["title"]
end
end
end
end
Expand Down
18 changes: 18 additions & 0 deletions spec/site_github_munger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,24 @@
expect(site.config["description"]).to eql(":octocat: `site.github`")
end
end

context "with name set, but no title" do
let(:user_config) { { "name" => "My site name" } }

it "respects the site name" do
expect(site.config["name"]).to eql("My site name")
expect(site.config["title"]).to be_nil
end
end

context "with site name and title" do
let(:user_config) { { "name" => "Name", "title" => "Title" } }

it "respects the user's settings" do
expect(site.config["name"]).to eql("Name")
expect(site.config["title"]).to eql("Title")
end
end
end

context "with a client with no credentials" do
Expand Down