9
votes

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).

2
If you just need a static file server, you can use node-static. But, if the site's still building, the files may not actually be available yet.Jonathan Lonowski
Hmm.. Installs fine with npm, but when I try static in the site directory I get no console output and nothing visible at localhost:8080... not sure what I missed...cboettig

2 Answers

9
votes
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.

7
votes

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.