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

在我的计算机上,我访问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/

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

baseurl: /repo-name/
url: https://username.github.io/

但是在localhost上,它必须是:

baseurl: 
url: http://127.0.0.1:4000

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

<script src="js/ghapi.js"></script>

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

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

解决方法

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

jekyll serve --config _config.yml,debug.yml

调试文件可以包含:

name: MySite [DEBUG MODE]
debug: true
url: http://127.0.0.1:4000

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

相关文章

vue阻止冒泡事件 阻止点击事件的执行 &lt;div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些