Jekyll generates a static site in a given directory (by default, _site). Running jekyll serve builds the site and then sets up a server such that the site can be viewed locally on the specified port (e.g. localhost:4000 by default). I'm wondering if there is a way to activate this serve behavior without triggering the gem to recompile the site first.
Alternatively, it would be sufficient to use some other tool to serve the site from a localhost port without using jekyll, but I'm not sure how to do that (node.js?). While I can open the static files directly in a browser, this doesn't find all the relative url links (to css, etc) correctly, defaulting links such as /css/default.css to the root file://css/default.css instead, which of course does not exist there.
(This would be useful, for instance, because Jekyll takes quite some time to build a large site, and certain plugins I use need internet access to various APIs. It would be nice to view the site offline without triggering these).
jekyll serve --skip-initial-build
This will serve the site, skipping the initial build process. Additional configuration options for building and serving the site can be found here.
If you just want to serve an already built _site directory, there are any number of ways to quickly run a web server locally. With ruby you can just cd into _site and use WEBrick like so:
ruby -rwebrick -e 'WEBrick::HTTPServer.new(:Port=>4000,:DocumentRoot=>".").start'
or python's SimpleHTTPServer:
python -mSimpleHTTPServer 4000
Both these set the port to 4000, but that could be any number.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With