ruby - How can I override the Jekyll build command to set some config options only when building? -
i'm using jekyll asset pipeline build website , i'd compress website (which takes 20 seconds) when i'm publishing it. have enable these values programmatically in config file:
asset_pipeline: bundle: false compress: false
i've tried code plugin isn't working. me why?
module jekyll module commands # overwrite here heavy work (like compressing html , stuff) # when building site, not when testing (which uses jekyll serve) class << build alias_method :_process, :process def process(options) require 'jekyll-press' options['asset_pipeline']['bundle'] = true options['asset_pipeline']['compress'] = true _process(options) end end end end
you don't need special gem - can pass multiple configuration files jekyll build
:
first, regular config file, settings needed, plus values disable compressing, since don't want run each time you're building locally:
_config.yml:
destination: _site source: src markdown: rdiscount # ... , many more settings needed asset_pipeline: bundle: false compress: false
then, need second config file publishing overrides values want different:
_config-publish.yml:
asset_pipeline: bundle: true compress: true
so when you're not publishing, run jekyll build
before.
but when you're publishing, pass both config files in right order:
jekyll build --config _config.yml,_config-publish.yml
jekyll apply them in order passed them, settings in second file overwrite ones in first file, , bundle
, compress
set true
in end.
in case can't control parameters passed jekyll build
(maybe on github pages? never used it, maybe...) can same thing, other way round:
- set
bundle
,compress
true
in default config file - whenever you're not publishing, use second
_config-dev.yml
file setbundle
,compress
false
again
Comments
Post a Comment