diff --git a/lib/jekyll-github-metadata/ghp_metadata_generator.rb b/lib/jekyll-github-metadata/ghp_metadata_generator.rb index 925ab9f..6a73f46 100644 --- a/lib/jekyll-github-metadata/ghp_metadata_generator.rb +++ b/lib/jekyll-github-metadata/ghp_metadata_generator.rb @@ -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 diff --git a/lib/jekyll-github-metadata/pages.rb b/lib/jekyll-github-metadata/pages.rb index bbf3a73..0306077 100644 --- a/lib/jekyll-github-metadata/pages.rb +++ b/lib/jekyll-github-metadata/pages.rb @@ -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 @@ -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]) diff --git a/spec/pages_spec.rb b/spec/pages_spec.rb index 29cc66f..f7a0ec0 100644 --- a/spec/pages_spec.rb +++ b/spec/pages_spec.rb @@ -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 @@ -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