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
4 changes: 2 additions & 2 deletions lib/jekyll-github-metadata/ghp_metadata_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def drop
@drop ||= MetadataDrop.new(site)
end

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

repo = drop.send(:repository)
site.config["url"] ||= repo.url_without_path
Expand Down
13 changes: 12 additions & 1 deletion lib/jekyll-github-metadata/pages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class << self
"PAGES_PAGES_HOSTNAME" => "github.io".freeze,
"SSL" => "false".freeze,
"SUBDOMAIN_ISOLATION" => "false".freeze,
"PAGES_PREVIEW_HTML_URL" => nil
"PAGES_PREVIEW_HTML_URL" => nil,
"PAGE_BUILD_ID" => nil
}.freeze

# Whether the GitHub instance supports HTTPS
Expand Down Expand Up @@ -75,6 +76,16 @@ def pages_hostname
trim_last_slash env_var("PAGES_PAGES_HOSTNAME", intermediate_default)
end

def page_build?
!env_var("PAGE_BUILD_ID").to_s.empty?
end

def configuration
(methods - Object.methods - [:configuration]).sort.each_with_object({}) do |meth, memo|
memo[meth.to_s] = public_send(meth)
end
end

private
def env_var(key, intermediate_default = nil)
!ENV[key].to_s.empty? ? ENV[key] : (intermediate_default || DEFAULTS[key])
Expand Down
35 changes: 35 additions & 0 deletions spec/pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,29 @@
end
end

context ".configuration" do
it "returns the entire configuration" do
expect(described_class.configuration).to eql({
"api_url" => "https://api.github.com",
"custom_domains_enabled?" => true,
"development?" => false,
"dotcom?" => false,
"enterprise?" => false,
"env" => "test",
"github_hostname" => "github.com",
"github_url" => "https://github.com",
"help_url" => "https://help.github.com",
"page_build?" => false,
"pages_hostname" => "github.io",
"repo_pages_html_url_preview?" => nil,
"scheme" => "https",
"ssl?" => true,
"subdomain_isolation?" => false,
"test?" => true
})
end
end

context ".env" do
it "picks up on PAGES_ENV" do
with_env("PAGES_ENV", "halp") do
Expand Down Expand Up @@ -113,4 +136,16 @@
end
end
end

context ".page_build?" do
it "returns true when $PAGE_BUILD_ID is set" do
with_env "PAGE_BUILD_ID", "123" do
expect(described_class.page_build?).to be(true)
end
end

it "returns false by default" do
expect(described_class.page_build?).to be(false)
end
end
end