Site root: Github Pages vs. `jekyll --server`

后端 未结 5 754
走了就别回头了
走了就别回头了 2020-12-24 08:20

When I run jekyll --server my site is available at http://localhost:4000/, but when I deploy to GitHub Project Pages, it\'s available at http

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-24 09:13

    This problem arises because the root directory is always the user url (user.github.com), in both user and project pages. I found a solution to this: Configure the url variable in the _config.yml file to the github project page:

    safe: true
    ...
    url: "http://user.github.io/project-name"
    

    then, in the layouts, use absolute references, using the site.url variable to do that:

    
    

    and run the server using:

    $jekyll --server --url=http://localhost:4000
    

    The command line option overwrite the setting in the configuration file in local mode. With those settings, I get all the links pointing to the right place, both hosted in github and in local mode.


    UPDATE: Jekyll 1.0 Since Jekyll reached 1.0, the aforemetioned options server and url and its respective command line options --server and --url have been deprecated. Instructions for the new version:

    In the _config.yml file, add the variable baseurl (without trailing slash):

    baseurl: "http://user.github.io/project-name"
    

    In the layouts or pages, use absolute references, using the site.baseurl variable:

    
    

    and then, run the local server (the baseurl option is empty on purpose):

    $ jekyll serve --watch --baseurl=
    

    More details about the changes in the docs.

提交回复
热议问题