From 91afe6c2d81569eb57a3ffa278daa1e32fa8e8cb Mon Sep 17 00:00:00 2001 From: Michael Rose Date: Wed, 16 Nov 2016 11:21:56 -0500 Subject: [PATCH] Add `rake preview` task for testing `/test` during theme development --- README.md | 6 ++++ Rakefile | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ test/_config.yml | 6 ++-- 3 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 Rakefile diff --git a/README.md b/README.md index d070a9d2..84f7d316 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,12 @@ To help me out try to avoid creating pull requests on `master` and instead branc Theme documentation and demo pages can be found in the [`/docs`](docs) if submitting improvements, typo corrections, etc. +## Development + +To set up your environment to develop this theme, run `bundle install`. + +To test the theme, run `bundle exec rake preview` and open your browser at `http://localhost:4000/test/`. This starts a Jekyll server using your theme and the contents of the `test/` directory. As you make modifications to your theme and to the example site, your site will regenerate and you should see the changes in the browser after a refresh. + --- ## Credits diff --git a/Rakefile b/Rakefile new file mode 100644 index 00000000..e50d89f8 --- /dev/null +++ b/Rakefile @@ -0,0 +1,75 @@ +require "bundler/gem_tasks" +require "jekyll" +require "listen" + +def listen_ignore_paths(base, options) + [ + /_config\.ya?ml/, + /_site/, + /\.jekyll-metadata/ + ] +end + +def listen_handler(base, options) + site = Jekyll::Site.new(options) + Jekyll::Command.process_site(site) + proc do |modified, added, removed| + t = Time.now + c = modified + added + removed + n = c.length + relative_paths = c.map{ |p| Pathname.new(p).relative_path_from(base).to_s } + print Jekyll.logger.message("Regenerating:", "#{relative_paths.join(", ")} changed... ") + begin + Jekyll::Command.process_site(site) + puts "regenerated in #{Time.now - t} seconds." + rescue => e + puts "error:" + Jekyll.logger.warn "Error:", e.message + Jekyll.logger.warn "Error:", "Run jekyll build --trace for more information." + end + end +end + +task :preview do + base = Pathname.new('.').expand_path + options = { + "source" => base.join('test').to_s, + "destination" => base.join('test/_site').to_s, + "force_polling" => false, + "serving" => true, + "theme" => "minimal-mistakes-jekyll" + } + + options = Jekyll.configuration(options) + + ENV["LISTEN_GEM_DEBUGGING"] = "1" + listener = Listen.to( + base.join("_includes"), + base.join("_layouts"), + base.join("_sass"), + base.join("assets"), + options["source"], + :ignore => listen_ignore_paths(base, options), + :force_polling => options['force_polling'], + &(listen_handler(base, options)) + ) + + begin + listener.start + Jekyll.logger.info "Auto-regeneration:", "enabled for '#{options["source"]}'" + + unless options['serving'] + trap("INT") do + listener.stop + puts " Halting auto-regeneration." + exit 0 + end + + loop { sleep 1000 } + end + rescue ThreadError + # You pressed Ctrl-C, oh my! + end + + Jekyll::Commands::Serve.process(options) +end diff --git a/test/_config.yml b/test/_config.yml index ee2135d3..8f614a4d 100644 --- a/test/_config.yml +++ b/test/_config.yml @@ -14,7 +14,7 @@ title_separator : "-" name : "Your Name" description : "Minimal Mistakes theme test." url : # the base hostname & protocol for your site e.g. "https://mmistakes.github.io" -baseurl : # the subpath of your site, e.g. "/blog" +baseurl : "/test" repository : # GitHub username/repo-name e.g. "mmistakes/minimal-mistakes" teaser : # path of fallback teaser image, e.g. "/assets/images/500x300.png" # breadcrumbs : false # true, false (default) @@ -57,7 +57,7 @@ yandex_site_verification : # Social Sharing twitter: - username : + username : "mmistakes" facebook: username : app_id : @@ -102,7 +102,7 @@ author: stackoverflow : # "123456/username" (the last part of your profile url, e.g. http://stackoverflow.com/users/123456/username) steam : tumblr : - twitter : + twitter : "mmistakes" vine : weibo : xing :