8000 Use owner name as site title for User and Organization sites. (#197) · jekyll/github-metadata@0efda2e · GitHub
[go: up one dir, main page]

Skip to content

Commit 0efda2e

Browse files
authored
Use owner name as site title for User and Organization sites. (#197)
Merge pull request 197
1 parent dc434d0 commit 0efda2e

9 files changed

+270
-1
lines changed

lib/jekyll-github-metadata/metadata_drop.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def keys
4848
def_delegator :repository, :tagline, :project_tagline
4949
def_delegator :repository, :owner_metadata, :owner
5050
def_delegator :repository, :owner, :owner_name
51+
def_delegator :repository, :owner_display_name, :owner_display_name
5152
def_delegator :repository, :owner_url, :owner_url
5253
def_delegator :repository, :owner_gravatar_url, :owner_gravatar_url
5354
def_delegator :repository, :repository_url, :repository_url

lib/jekyll-github-metadata/repository.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ def repo_pages_info_opts
6464
end
6565
end
6666

67+
def owner_display_name
68+
owner_metadata.name
69+
end
70+
6771
def owner_metadata
6872
@owner_metadata ||= Jekyll::GitHubMetadata::Owner.new(owner)
6973
end

lib/jekyll-github-metadata/site_github_munger.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ def add_title_and_description_fallbacks!
5555
msg << "Jekyll GitHub Metadata will not set site.title to the repository's name."
5656
Jekyll::GitHubMetadata.log :warn, msg
5757
else
58-
site.config["title"] ||= Value.new("title", proc { |_c, r| r.name })
58+
site.config["title"] ||= Value.new("title", proc { |_context, repository|
59+
if repository.project_page?
60+
repository.name
61+
else
62+
repository.owner_display_name || repository.owner
63+
end
64+
})
5965
end
6066
site.config["description"] ||= Value.new("description", proc { |_c, r| r.tagline })
6167
end

spec/site_github_munger_spec.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,64 @@
132132
end
133133
end
134134

135+
context "generating repo for user with displayname" do
136+
before(:each) do
137+
ENV["JEKYLL_ENV"] = "production"
138+
ENV["PAGES_REPO_NWO"] = "jekyllbot/jekyllbot.github.io"
139+
stub_api("/repos/jekyllbot/jekyllbot.github.io", "user_site")
140+
stub_api_404("/orgs/jekyllbot")
141+
stub_api("/users/jekyllbot", "user_with_displayname")
142+
subject.munge!
143+
end
144+
145+
it "sets title to user's displayname" do
146+
expect(site.config["title"]).to eql("Jekyll Bot")
147+
end
148+
end
149+
150+
context "generating repo for user without displayname" do
151+
before(:each) do
152+
ENV["JEKYLL_ENV"] = "production"
153+
ENV["PAGES_REPO_NWO"] = "jekyllbot/jekyllbot.github.io"
154+
stub_api("/repos/jekyllbot/jekyllbot.github.io", "user_site")
155+
stub_api_404("/orgs/jekyllbot")
156+
stub_api("/users/jekyllbot", "user_without_displayname")
157+
subject.munge!
158+
end
159+
160+
it "sets title to user's login" do
161+
expect(site.config["title"]).to eql("jekyllbot")
162+
end
163+
end
164+
165+
context "generating repo for org with displayname" do
166+
before(:each) do
167+
ENV["JEKYLL_ENV"] = "production"
168+
ENV["PAGES_REPO_NWO"] = "jekyll/jekyll.github.io"
169+
stub_api("/repos/jekyll/jekyll.github.io", "repo")
170+
stub_api("/orgs/jekyll", "org",)
171+
subject.munge!
172+
end
173+
174+
it "sets title to org's displayname" do
175+
expect(site.config["title"]).to eql("Jekyll")
176+
end
177+
end
178+
179+
context "generating repo for org without displayname" do
180+
before(:each) do
181+
ENV["JEKYLL_ENV"] = "production"
182+
ENV["PAGES_REPO_NWO"] = "jekyll/jekyll.github.io"
183+
stub_api("/repos/jekyll/jekyll.github.io", "repo")
184+
stub_api("/orgs/jekyll", "org_without_displayname",)
185+
subject.munge!
186+
end
187+
188+
it "sets title to org's login" do
189+
expect(site.config["title"]).to eql("jekyll")
190+
end
191+
end
192+
135193
context "with a client with no credentials" do
136194
before(:each) do
137195
Jekyll::GitHubMetadata.client = Jekyll::GitHubMetadata::Client.new(:access_token => "")

spec/spec_helpers/integration_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def expected_values
1717
"project_tagline" => ":octocat: `site.github`",
1818
"owner" => Regexp.new('"html_url"=>"https://github.com/jekyll",\s+"id"=>3083652'),
1919
"owner_name" => "jekyll",
20+
"owner_display_name" => "Jekyll",
2021
"owner_url" => "https://github.com/jekyll",
2122
"owner_gravatar_url" => "https://github.com/jekyll.png",
2223
"repository_url" => "https://github.com/jekyll/github-metadata",
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"login": "jekyll",
3+
"id": 3083652,
4+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjMwODM2NTI=",
5+
"url": "https://api.github.com/orgs/jekyll",
6+
"repos_url": "https://api.github.com/orgs/jekyll/repos" EED3 ,
7+
"events_url": "https://api.github.com/orgs/jekyll/events",
8+
"hooks_url": "https://api.github.com/orgs/jekyll/hooks",
9+
"issues_url": "https://api.github.com/orgs/jekyll/issues",
10+
"members_url": "https://api.github.com/orgs/jekyll/members{/member}",
11+
"public_members_url": "https://api.github.com/orgs/jekyll/public_members{/member}",
12+
"avatar_url": "https://avatars0.githubusercontent.com/u/3083652?v=4",
13+
"description": "Jekyll is a blog-aware, static site generator in Ruby.",
14+
"name": null,
15+
"company": null,
16+
"blog": "https://jekyllrb.com",
17+
"location": null,
18+
"email": "",
19+
"is_verified": true,
20+
"has_organization_projects": true,
21+
"has_repository_projects": true,
22+
"public_repos": 50,
23+
"public_gists": 0,
24+
"followers": 0,
25+
"following": 0,
26+
"html_url": "https://github.com/jekyll",
27+
"created_at": "2012-12-19T19:37:35Z",
28+
"updated_at": "2019-01-27T15:27:32Z",
29+
"type": "Organization"
30+
}

spec/webmock/api_get_user_site.json

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"id": 50212532,
3+
"node_id": "MDEwOlJlcG9zaXRvcnk1MDIxMjUzMg==",
4+
"name": "github-pages-site",
5+
"full_name": "jekyllbot/github-pages-site",
6+
"private": false,
7+
"owner": {
8+
"login": "jekyllbot",
9+
"id": 6166343,
10+
"node_id": "MDQ6VXNlcjYxNjYzNDM=",
11+
"avatar_url": "https://avatars.githubusercontent.com/u/6166343?v=4",
12+
"gravatar_id": "",
13+
"url": "https://api.github.com/users/jekyllbot",
14+
"html_url": "https://github.com/jekyllbot",
15+
"followers_url": "https://api.github.com/users/jekyllbot/followers",
16+
"following_url": "https://api.github.com/users/jekyllbot/following{/other_user}",
17+
"gists_url": "https://api.github.com/users/jekyllbot/gists{/gist_id}",
18+
"starred_url": "https://api.github.com/users/jekyllbot/starred{/owner}{/repo}",
19+
"subscriptions_url": "https://api.github.com/users/jekyllbot/subscriptions",
20+
"organizations_url": "https://api.github.com/users/jekyllbot/orgs",
21+
"repos_url": "https://api.github.com/users/jekyllbot/repos",
22+
"events_url": "https://api.github.com/users/jekyllbot/events{/privacy}",
23+
"received_events_url": "https://api.github.com/users/jekyllbot/received_events",
24+
"type": "User",
25+
"site_admin": false
26+
},
27+
"html_url": "https://github.com/jekyllbot/github-pages-site",
28+
"description": "Example GitHub Pages Site",
29+
"fork": false,
30+
"url": "https://api.github.com/repos/jekyllbot/github-pages-site",
31+
"forks_url": "https://api.github.com/repos/jekyllbot/github-pages-site/forks",
32+
"keys_url": "https://api.github.com/repos/jekyllbot/github-pages-site/keys{/key_id}",
33+
"collaborators_url": "https://api.github.com/repos/jekyllbot/github-pages-site/collaborators{/collaborator}",
34+
"teams_url": "https://api.github.com/repos/jekyllbot/github-pages-site/teams",
35+
"hooks_url": "https://api.github.com/repos/jekyllbot/github-pages-site/hooks",
36+
"issue_events_url": "https://api.github.com/repos/jekyllbot/github-pages-site/issues/events{/number}",
37+
"events_url": "https://api.github.com/repos/jekyllbot/github-pages-site/events",
38+
"assignees_url": "https://api.github.com/repos/jekyllbot/github-pages-site/assignees{/user}",
39+
"branches_url": "https://api.github.com/repos/jekyllbot/github-pages-site/branches{/branch}",
40+
"tags_url": "https://api.github.com/repos/jekyllbot/github-pages-site/tags",
41+
"blobs_url": "https://api.github.com/repos/jekyllbot/github-pages-site/git/blobs{/sha}",
42+
"git_tags_url": "https://api.github.com/repos/jekyllbot/github-pages-site/git/tags{/sha}",
43+
"git_refs_url": "https://api.github.com/repos/jekyllbot/github-pages-site/git/refs{/sha}",
44+
"trees_url": "https://api.github.com/repos/jekyllbot/github-pages-site/git/trees{/sha}",
45+
"statuses_url": "https://api.github.com/repos/jekyllbot/github-pages-site/statuses/{sha}",
46+
"languages_url": "https://api.github.com/repos/jekyllbot/github-pages-site/languages",
47+
"stargazers_url": "https://api.github.com/repos/jekyllbot/github-pages-site/stargazers",
48+
"contributors_url": "https://api.github.com/repos/jekyllbot/github-pages-site/contributors",
49+
"subscribers_url": "https://api.github.com/repos/jekyllbot/github-pages-site/subscribers",
50+
"subscription_url": "https://api.github.com/repos/jekyllbot/github-pages-site/subscription",
51+
"commits_url": "https://api.github.com/repos/jekyllbot/github-pages-site/commits{/sha}",
52+
"git_commits_url": "https://api.github.com/repos/jekyllbot/github-pages-site/git/commits{/sha}",
53+
"comments_url": "https://api.github.com/repos/jekyllbot/github-pages-site/comments{/number}",
54+
"issue_comment_url": "https://api.github.com/repos/jekyllbot/github-pages-site/issues/comments{/number}",
55+
"contents_url": "https://api.github.com/repos/jekyllbot/github-pages-site/contents/{+path}",
56+
"compare_url": "https://api.github.com/repos/jekyllbot/github-pages-site/compare/{base}...{head}",
57+
"merges_url": "https://api.github.com/repos/jekyllbot/github-pages-site/merges",
58+
"archive_url": "https://api.github.com/repos/jekyllbot/github-pages-site/{archive_format}{/ref}",
59+
"downloads_url": "https://api.github.com/repos/jekyllbot/github-pages-site/downloads",
60+
"issues_url": "https://api.github.com/repos/jekyllbot/github-pages-site/issues{/number}",
61+
"pulls_url": "https://api.github.com/repos/jekyllbot/github-pages-site/pulls{/number}",
62+
"milestones_url": "https://api.github.com/repos/jekyllbot/github-pages-site/milestones{/number}",
63+
"notifications_url": "https://api.github.com/repos/jekyllbot/github-pages-site/notifications{?since,all,participating}",
64+
"labels_url": "https://api.github.com/repos/jekyllbot/github-pages-site/labels{/name}",
65+
"releases_url": "https://api.github.com/repos/jekyllbot/github-pages-site/releases{/id}",
66+
"deployments_url": "https://api.github.com/repos/jekyllbot/github-pages-site/deployments",
67+
"created_at": "2016-01-22T22:53:40Z",
68+
"updated_at": "2017-07-13T20:03:10Z",
69+
"pushed_at": "2016-11-20T00:18:58Z",
70+
"git_url": "git://github.com/jekyllbot/github-pages-site.git",
71+
"ssh_url": "git@github.com:jekyllbot/github-pages-site.git",
72+
"clone_url": "https://github.com/jekyllbot/github-pages-site.git",
73+
"svn_url": "https://github.com/jekyllbot/github-pages-site",
74+
"homepage": "https://jekyllbot.github.io/github-pages-site/",
75+
"size": 16,
76+
"stargazers_count": 6,
77+
"watchers_count": 6,
78+
"language": "JavaScript",
79+
"has_issues": true,
80+
"has_projects": true,
81+
"has_downloads": true,
82+
"has_wiki": false,
83+
"has_pages": true,
84+
"forks_count": 6,
85+
"mirror_url": null,
86+
"archived": false,
87+
"disabled": false,
88+
"open_issues_count": 0,
89+
"license": {
90+
"key": "mit",
91+
"name": "MIT License",
92+
"spdx_id": "MIT",
93+
"url": "https://api.github.com/licenses/mit",
94+
"node_id": "MDc6TGljZW5zZTEz"
95+
},
96+
"forks": 6,
97+
"open_issues": 0,
98+
"watchers": 6,
99+
"default_branch": "gh-pages",
100+
"temp_clone_token": null,
101+
"network_count": 6,
102+
"subscribers_count": 1
103+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"login": "jekyllbot",
3+
"id": 6166343,
4+
"node_id": "MDQ6VXNlcjYxNjYzNDM=",
5+
"avatar_url": "https://avatars0.githubusercontent.com/u/6166343?v=4",
6+
"gravatar_id": "",
7+
"url": "https://api.github.com/users/jekyllbot",
8+
"html_url": "https://github.com/jekyllbot",
9+
"followers_url": "https://api.github.com/users/jekyllbot/followers",
10+
"following_url": "https://api.github.com/users/jekyllbot/following{/other_user}",
11+
"gists_url": "https://api.github.com/users/jekyllbot/gists{/gist_id}",
12+
"starred_url": "https://api.github.com/users/jekyllbot/starred{/owner}{/repo}",
13+
"subscriptions_url": "https://api.github.com/users/jekyllbot/subscriptions",
14+
"organizations_url": "https://api.github.com/users/jekyllbot/orgs",
15+
"repos_url": "https://api.github.com/users/jekyllbot/repos",
16+
"events_url": "https://api.github.com/users/jekyllbot/events{/privacy}",
17+
"received_events_url": "https://api.github.com/users/jekyllbot/received_events",
18+
"type": "User",
19+
"site_admin": false,
20+
"name": "Jekyll Bot",
21+
"company": null,
22+
"blog": "https://github.com/parkr/auto-reply",
23+
"location": null,
24+
"email": null,
25+
"hireable": null,
26+
"bio": "I help make working with @jekyll fun and easy.",
27+
"public_repos": 2,
28+
"public_gists": 0,
29+
"followers": 68,
30+
"following": 0,
31+
"created_at": "2013-12-12T02:49:00Z",
32+
"updated_at": "2017-12-05T21:23:41Z"
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"login": "jekyllbot",
3+
"id": 6166343,
4+
"node_id": "MDQ6VXNlcjYxNjYzNDM=",
5+
"avatar_url": "https://avatars0.githubusercontent.com/u/6166343?v=4",
6+
"gravatar_id": "",
7+
"url": "https://api.github.com/users/jekyllbot",
8+
"html_url": "https://github.com/jekyllbot",
9+
"followers_url": "https://api.github.com/users/jekyllbot/followers",
10+
"following_url": "https://api.github.com/users/jekyllbot/following{/other_user}",
11+
"gists_url": "https://api.github.com/users/jekyllbot/gists{/gist_id}",
12+
"starred_url": "https://api.github.com/users/jekyllbot/starred{/owner}{/repo}",
13+
"subscriptions_url": "https://api.github.com/users/jekyllbot/subscriptions",
14+
"organizations_url": "https://api.github.com/users/jekyllbot/orgs",
15+
"repos_url": "https://api.github.com/users/jekyllbot/repos",
16+
"events_url": "https://api.github.com/users/jekyllbot/events{/privacy}",
17+
"received_events_url": "https://api.github.com/users/jekyllbot/received_events",
18+
"type": "User",
19+
"site_admin": false,
20+
"name": null,
21+
"company": null,
22+
"blog": "https://github.com/parkr/auto-reply",
23+
"location": null,
24+
"email": null,
25+
"hireable": null,
26+
"bio": "I help make working with @jekyll fun and easy.",
27+
"public_repos": 2,
28+
"public_gists": 0,
29+
"followers": 68,
30+
"following": 0,
31+
"created_at": "2013-12-12T02:49:00Z",
32+
"updated_at": "2017-12-05T21:23:41Z"
33+
}

0 commit comments

Comments
 (0)
0