微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在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.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐