Nishant
Nishant

Reputation: 916

Running jekyll generated files without jekyll / local server?

I have just started working with Jekyll. As a front-end developer i have to create a lot of static pages for web applications before they go into development.

I am trying to run jekyll generated files inside the _site folder without a server as sometime as part of my workflow i have to send plain static HTML files to other dev team or show to clients during a presentation (sometimes as a zip folder so can't hardcode any specific path in config file).

I am not able to run jekyll files from a local folder like file:///C:/Users/ as all the links and assets only work while running from a jekyll server.

Is there any way that this can be achieved.

Thanks

Upvotes: 12

Views: 4905

Answers (3)

David Jacquel
David Jacquel

Reputation: 52829

Edit: I've just posted a new answer using relatives links. Which is more portable solution.

I see three solutions to your problem :

Distribute your code via Github Pages

Use a public or a private repository on Github Pages to serve you work. You can use the ideas developed by Octopress to store your code and the generated files on two different branches of your repository and give access to your plain html to developers.

Configure Jekyll to (nearly) work on file system

By using the baseurl configuration variable in _config.yml.

If the site's zip is unzipped in C:/Users/toto/mysite, add :

# No trailing slash
baseurl: "file:///C:/Users/toto/mysite"

In default Jekyll templates, assets are called with :

<link rel="stylesheet" href="{{ "/css/main.css" | prepend: site.baseurl }}">
or
<script src="{{ site.baseurl }}/assets/javascripts/script.js"></script>

Links and images must make use of baseurl to :

# html link
<a href="{{ site.baseurl }}{{ page.url }}">{{ page.title }}</a>

# markdown link
[{{ page.title }}]({{ site.baseurl }}{{ page.url }})

# html image
<img src="{{ site.baseurl }}/assets/myimage.png">

# markdown image
![Img title]({{ site.baseurl }}/assets/myimage.png)

Note : Any page that has a permalink set to end with folder/index.html (eg: permalink: /about/) will result in having link targeting folder/ and land on the folder's files listing page.

Give a try to an exotic solution for Win users

You can give a try to Portable Jekyll that seems to work on windows.

Upvotes: 2

csknk
csknk

Reputation: 2039

You can view a built Jekyll site without a server - but it needs an extra tool.

Serve your Jekyll site as normal, and use wget to clone your served site in flat format. This will work on a linux system:

  • Serve the Jekyll site
  • Open a new terminal, create & move into a target directory
  • Run wget from this directory
  • Send the resulting directory to your client

You may need to play about with wget settings, but if your site is served on port 4000 you could try something like this:

wget --convert-links -r http://127.0.0.1:4000/

You'll probably need to be careful with the recursive flag. See http://www.gnu.org/software/wget/

Upvotes: 17

Subhas
Subhas

Reputation: 14408

This is fundamentally impossible with Jekyll, because the index page is a different hierarchy (/index) and each blog post is a nested URL (/posts/about). So the URLs for things like CSS and Javascript will have to be different for each page. For a post it should be "../css/..." and for index it should be "./css/". That is not possible without a running server.

So here are some options for you:

  • Pass "." as the base url. So your styles will become './css/'. Now your index page will work fine, but blog posts won't (they need '../')

    jekyll serve --baseurl .
    
  • Pass the current folder as base URL. Now you don't need a server, but your _site folder is tied to your machine's folder, and not exactly portable.

    jekyll serve --baseurl $(pwd)
    
  • Use a lightweight server. This will start a simple server on the current folder (so make sure you go into _site folder), so you don't need jekyll to be installed. This is available by default in python, so you don't have to install anything separate, as long as python is installed.

    python -m SimpleHTTPServer <port>
    

Upvotes: 9

Related Questions