如何在localhost和远程服务器上轻松管理Jekyll网页的不同基本URL?

Tom*_*ica 4 jekyll

在我的计算机上,我在URL上访问我的测试网页http://127.0.0.1:4000.在服务器上,它将在GitHub页面上,这意味着https://username.github.io/repo-name/.

_config.yml我看到以下相关设置:

# Uncomment if you are planning to run the blog in a subdirectory
# Note - if you enable this, and attempt to view your site locally you have to use the baseurl in your local path.
# Example, you must use http://localhost:4000/path/to/blog
#baseurl: /path/to/blog 
baseurl: 

# The URL of your actual domain. This will be used to make absolute links in the RSS feed.
url: http://yourdomain.com/
Run Code Online (Sandbox Code Playgroud)

所以对于GitHub服务器我需要它:

baseurl: /repo-name/
url: https://username.github.io/
Run Code Online (Sandbox Code Playgroud)

但是在localhost上,必须是:

baseurl: 
url: http://127.0.0.1:4000
Run Code Online (Sandbox Code Playgroud)

这些设置是必要的,因为没有它们,我将为使用相对路径的资源获得404错误:

<script src="js/ghapi.js"></script>
Run Code Online (Sandbox Code Playgroud)

"NetworkError: 404 Not Found - http://127.0.0.1:4000/download/js/ghapi.js"

路径应该是http://127.0.0.1:4000/js/ghapi.js但是因为页面/download被添加到脚本文件的相对URL.

我需要处理这个问题,我该怎么做?

Tom*_*ica 7

最好的解决方案是拥有两个配置文件.另外一个,debug.yml覆盖了基本设置中的一些设置.可以使用以下命令加载这两个设置文件:

jekyll serve --config _config.yml,debug.yml
Run Code Online (Sandbox Code Playgroud)

调试文件可以包含:

name: MySite [DEBUG MODE]
debug: true
url: http://127.0.0.1:4000
Run Code Online (Sandbox Code Playgroud)

这里的优点是不需要更改设置文件,只需使用不同的命令来运行jekyll.