Running jekyll generated files without jekyll / local server?

前端 未结 3 672
無奈伤痛
無奈伤痛 2021-01-04 20:42

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 t

相关标签:
3条回答
  • 2021-01-04 21:03

    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>
      
    0 讨论(0)
  • 2021-01-04 21:06

    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/

    0 讨论(0)
  • 2021-01-04 21:22

    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.

    0 讨论(0)
提交回复
热议问题