8000 warn and do nothing when site.name is set (#113) · inntran/github-metadata@a03b71e · GitHub
[go: up one dir, main page]

Skip to content

Commit a03b71e

Browse files
benbalterjekyllbot
authored andcommitted
warn and do nothing when site.name is set (jekyll#113)
Merge pull request 113
1 parent 3765032 commit a03b71e

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

lib/jekyll-github-metadata/site_github_munger.rb

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,31 @@ def add_url_and_baseurl_fallbacks!
4747
site.config["baseurl"] = Value.new("baseurl", proc { |_c, r| r.baseurl })
4848
end
4949

50+
def add_title_and_description_fallbacks!
51+
if should_warn_about_site_name?
52+
msg = "site.name is set in _config.yml, but many plugins and themes expect "
53+
msg << "site.title to be used instead. To avoid potential inconsistency, "
54+
msg << "Jekyll GitHub Metadata will not set site.title to the repository's name."
55+
Jekyll::GitHubMetadata.log :warn, msg
56+
else
57+
site.config["title"] ||= Value.new("title", proc { |_c, r| r.name })
58+
end
59+
site.config["description"] ||= Value.new("description", proc { |_c, r| r.tagline })
60+
end
61+
5062
# Set the baseurl only if it is `nil` or `/`
5163
# Baseurls should never be "/". See http://bit.ly/2s1Srid
5264
def should_set_baseurl?
5365
site.config["baseurl"].nil? || site.config["baseurl"] == "/"
5466
end
5567

56-
def add_title_and_description_fallbacks!
57-
site.config["title"] ||= Value.new("title", proc { |_c, r| r.name })
58-
site.config["description"] ||= Value.new("description", proc { |_c, r| r.tagline })
59-
end
60-
6168
def should_add_url_fallbacks?
6269
Jekyll.env == "production" || Pages.page_build?
6370
end
71+
72+
def should_warn_about_site_name?
73+
site.config["name"] && !site.config["title"]
74+
end
6475
end
6576
end
6677
end

spec/site_github_munger_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,24 @@
112112
expect(site.config["description"]).to eql(":octocat: `site.github`")
113113
end
114114
end
115+
116+
context "with name set, but no title" do
117+
let(:user_config) { { "name" => "My site name" } }
118+
119+
it "respects the site name" do
120+
expect(site.config["name"]).to eql("My site name")
121+
expect(site.config["title"]).to be_nil
122+
end
123+
end
124+
125+
context "with site name and title" do
126+
let(:user_config) { { "name" => "Name", "title" => "Title" } }
127+
128+
it "respects the user's settings" do
129+
expect(site.config["name"]).to eql("Name")
130+
expect(site.config["title"]).to eql("Title")
131+
end
132+
end
115133
end
116134

117135
context "with a client with no credentials" do

0 commit comments

Comments
 (0)
0