Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove gem-based themes, replace with remote themes #772

Merged
merged 2 commits into from Jul 22, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/github-pages/configuration.rb
Expand Up @@ -107,6 +107,7 @@ def effective_config(user_config)
# Allow theme to be explicitly disabled via "theme: null"
config["theme"] = user_config["theme"] if user_config.key?("theme")

migrate_theme_to_remote_theme(config)
exclude_cname(config)

# Merge overwrites into user config
Expand Down Expand Up @@ -156,6 +157,16 @@ def restrict_and_config_markdown_processor(config)
}
end

# If the user has set a 'theme', then see if we can automatically use remote theme instead.
def migrate_theme_to_remote_theme(config)
return unless config["theme"]
return unless GitHubPages::Plugins::THEMES_TO_CONVERT_TO_REMOTE_THEMES.key?(config["theme"])

theme_name = config.delete("theme")
config["remote_theme"] ||= GitHubPages::Plugins::THEMES_TO_CONVERT_TO_REMOTE_THEMES[theme_name]
config["plugins"] = Array(config["plugins"]).concat(["jekyll-remote-theme"]).uniq
end

# If the user's 'exclude' config is the default, also exclude the CNAME
def exclude_cname(config)
return unless config["exclude"].eql? Jekyll::Configuration::DEFAULTS["exclude"]
Expand Down
32 changes: 18 additions & 14 deletions lib/github-pages/plugins.rb
Expand Up @@ -48,21 +48,25 @@ class Plugins

# Themes
THEMES = {
"jekyll-swiss" => "1.0.0",
"minima" => "2.5.1",
"jekyll-theme-primer" => "0.5.4",
"jekyll-theme-architect" => "0.1.1",
"jekyll-theme-cayman" => "0.1.1",
"jekyll-theme-dinky" => "0.1.1",
"jekyll-theme-hacker" => "0.1.2",
"jekyll-theme-leap-day" => "0.1.1",
"jekyll-theme-merlot" => "0.1.1",
"jekyll-theme-midnight" => "0.1.1",
"jekyll-theme-minimal" => "0.1.1",
"jekyll-theme-modernist" => "0.1.1",
"jekyll-theme-slate" => "0.1.1",
"jekyll-theme-tactile" => "0.1.1",
"jekyll-theme-time-machine" => "0.1.1",
}.freeze

# Themes to convert to remote themes
THEMES_TO_CONVERT_TO_REMOTE_THEMES = {
"jekyll-swiss" => "broccolini/swiss",
"jekyll-theme-primer" => "pages-themes/primer@v0.5.4",
"jekyll-theme-architect" => "pages-themes/architect@v0.1.1",
"jekyll-theme-cayman" => "pages-themes/cayman@v0.1.1",
"jekyll-theme-dinky" => "pages-themes/dinky@v0.1.1",
"jekyll-theme-hacker" => "pages-themes/hacker@v0.1.1",
"jekyll-theme-leap-day" => "pages-themes/leap-day@v0.1.1",
"jekyll-theme-merlot" => "pages-themes/merlot@v0.1.1",
"jekyll-theme-midnight" => "pages-themes/midnight@v0.1.1",
"jekyll-theme-minimal" => "pages-themes/minimal@v0.1.1",
"jekyll-theme-modernist" => "pages-themes/modernist@v0.1.1",
"jekyll-theme-slate" => "pages-themes/slate@v0.1.1",
"jekyll-theme-tactile" => "pages-themes/tactile@v0.1.1",
"jekyll-theme-time-machine" => "pages-themes/time-machine@v0.1.1",
}
end
end
26 changes: 17 additions & 9 deletions spec/github-pages/configuration_spec.rb
Expand Up @@ -20,6 +20,7 @@
ENV.delete("DISABLE_WHITELIST")
ENV["JEKYLL_ENV"] = "test"
ENV["PAGES_REPO_NWO"] = "github/pages-gem"
stub_request_for_remote_theme(:repo => "pages-themes/primer", :revision => "v0.5.4", :filename => "primer-0.5.4.zip")
end

context "#effective_config" do
Expand Down Expand Up @@ -103,22 +104,32 @@
context "themes" do
context "with no theme set" do
it "sets the theme" do
expect(effective_config["plugins"]).to include("jekyll-remote-theme")
expect(site.theme).to_not be_nil
expect(site.theme).to be_a(Jekyll::Theme)
expect(site.theme.name).to eql("jekyll-theme-primer")
expect(site.theme.name).to eql("primer")
end
end

context "with a user-specified theme" do
let(:site) do
config = configuration.merge("theme" => "jekyll-theme-merlot")
Jekyll::Site.new(config)
let(:configuration) do
described_class.effective_config(
Jekyll.configuration(
test_config.merge("theme" => "jekyll-theme-merlot")
)
)
end

before(:each) do
stub_request_for_remote_theme(:repo => "pages-themes/merlot", :revision => "v0.1.1", :filename => "merlot-0.1.1.zip")
end

it "respects the theme" do
expect(configuration["theme"]).to be_nil
expect(configuration["remote_theme"]).to eq(GitHubPages::Plugins::THEMES_TO_CONVERT_TO_REMOTE_THEMES["jekyll-theme-merlot"])
expect(site.theme).to_not be_nil
expect(site.theme).to be_a(Jekyll::Theme)
expect(site.theme.name).to eql("jekyll-theme-merlot")
expect(site.theme.name).to eql("merlot")
end
end

Expand All @@ -133,10 +144,6 @@
end
end

it "plugins don't include jekyll remote theme" do
expect(effective_config["plugins"]).to_not include("jekyll-remote-theme")
end

context "with a remote theme" do
let(:test_config) do
{
Expand All @@ -149,6 +156,7 @@
end

it "plugins include jekyll remote theme" do
stub_request_for_remote_theme(:repo => "foo/bar", :revision => "HEAD", :filename => "primer-0.5.4.zip")
expect(effective_config["plugins"]).to include("jekyll-remote-theme")
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/github-pages/integration_spec.rb
Expand Up @@ -258,7 +258,7 @@ def rm_destination

context "jekyll-theme-primer" do
it "sets the theme" do
expect(contents).to match("Theme: jekyll-theme-primer")
expect(contents).to match("Theme: primer")
end

it "uses the theme" do
Expand Down
9 changes: 9 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -29,6 +29,15 @@ def tmp_dir
File.expand_path "../tmp", __dir__
end

def support_dir
File.expand_path "support", __dir__
end

def stub_request_for_remote_theme(repo:, revision:, filename:)
stub_request(:get, "https://codeload.github.com/#{repo}/zip/#{revision}").
to_return(:status => 200, :body => File.binread(File.join(support_dir, filename)), :headers => {"Content-Type" => "archive/zip"})
end

RSpec::Matchers.define :be_an_existing_file do
match { |path| File.exist?(path) }
end
Binary file added spec/support/merlot-0.1.1.zip
Binary file not shown.
Binary file added spec/support/primer-0.5.4.zip
Binary file not shown.