Thanks to visit codestin.com
Credit goes to github.com

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
18 changes: 16 additions & 2 deletions lib/jekyll-github-metadata/site_github_munger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ def munge!

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

return unless should_add_fallbacks?
add_url_and_baseurl_fallbacks!
add_title_and_description_fallbacks!
end

private
Expand All @@ -37,14 +40,25 @@ def drop

# Set `site.url` and `site.baseurl` if unset.
def add_url_and_baseurl_fallbacks!
return unless Jekyll.env == "production" || Pages.page_build?

repo = drop.send(:repository)
site.config["url"] ||= repo.url_without_path
if site.config["baseurl"].to_s.empty? && !["", "/"].include?(repo.baseurl)
site.config["baseurl"] = repo.baseurl
end
end

def add_title_and_description_fallbacks!
site.config["title"] ||= repository.name
site.config["description"] ||= repository.tagline
end

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

def repository
drop.send(:repository)
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 @@ -43,6 +43,24 @@
expect(site.config["baseurl"]).to eql("/github-metadata")
end
end

context "title and description" do
context "with title and description set" do
let(:user_config) do
{ "title" => "My title", "description" => "My description" }
end

it "respects the title and tagline" do
expect(site.config["title"]).to eql("My title")
expect(site.config["description"]).to eql("My description")
end
end

it "sets the title and description" do
expect(site.config["title"]).to eql("github-metadata")
expect(site.config["description"]).to eql(":octocat: `site.github`")
end
end
end

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