octopress
octopress copied to clipboard
Feature request: multiple config file, dev config file support
Since some site configuration can contain secrets which I would not like to commit to public repos, I like to keep them separate from the main config file, e.g. flickr api shared secret.
Also, when I am running a "rake preview" on my home box, I would like to change site.url
to localhost:4000
. Like many people, I am doing this by keeping another config file specifically for local development.
I would like to request for octopress to support both these scenarios.
As an example, here is what my Rakefile looks like to do this:
+JEKYLL_CONFIG = "_config.yml"
+site_config = YAML.load_file(JEKYLL_CONFIG)
+jekyll_configs = {:prod => [JEKYLL_CONFIG], :dev => [JEKYLL_CONFIG]}
+
+if site_config['extra_configs']
+ jekyll_configs[:prod].push *site_config['extra_configs']
+ jekyll_configs[:dev].push *site_config['extra_configs']
+end
+
+if site_config['dev_configs']
+ jekyll_configs[:dev].push *site_config['dev_configs']
+end
+
+jekyll_configs.each do |env, paths|
+ jekyll_configs[env] = paths.map {|p| File.expand_path p}.join(",")
+end
+
## -- Misc Configs -- ##
public_dir = "public" # compiled site directory
@@ -57,7 +78,7 @@
raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
puts "## Generating Site with Jekyll"
system "compass compile --css-dir #{source_dir}/stylesheets"
- system "jekyll build"
+ system "jekyll build --config #{jekyll_configs[:prod]}"
end
desc "Watch the site and regenerate when it changes"
@@ -65,7 +86,7 @@
raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
puts "Starting to watch source with Jekyll and Compass."
system "compass compile --css-dir #{source_dir}/stylesheets" unless File.exist?("#{source_dir}/stylesheets/screen.css")
- jekyllPid = Process.spawn({"OCTOPRESS_ENV"=>"preview"}, "jekyll build --watch")
+ jekyllPid = Process.spawn({"OCTOPRESS_ENV"=>"preview"}, "jekyll build --watch --config #{jekyll_configs[:dev]}")
compassPid = Process.spawn("compass watch")
trap("INT") {
@@ -81,7 +102,7 @@
raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
puts "Starting to watch source with Jekyll and Compass. Starting Rack on port #{server_port}"
system "compass compile --css-dir #{source_dir}/stylesheets" unless File.exist?("#{source_dir}/stylesheets/screen.css")
- jekyllPid = Process.spawn({"OCTOPRESS_ENV"=>"preview"}, "jekyll build --watch")
+ jekyllPid = Process.spawn({"OCTOPRESS_ENV"=>"preview"}, "jekyll build --watch --config #{jekyll_configs[:dev]}")
compassPid = Process.spawn("compass watch")
rackupPid = Process.spawn("rackup --port #{server_port}")
This allows me to have the following config file content.
extra_configs: ~/blog-secrets/blog.sandipb.net/_config.secrets.yml
dev_configs: _config_dev.yml
I am pretty new to Ruby, so my rakefile hack probably looks newbiesh, and there is probably a better way to do this. That is why I decided not to send a pull request :) But I would really like to keep my octopress code as much in sync with upstream as possible, which it will be if this feature is added.
Thanks, Sandip