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

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

概述在我的计算机上,我访问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# N 在我的计算机上,我访问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: trueurl: http://127.0.0.1:4000

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

总结

以上是内存溢出为你收集整理的如何在localhost和远程服务器上轻松管理Jekyll网页的不同基本URL?全部内容,希望文章能够帮你解决如何在localhost和远程服务器上轻松管理Jekyll网页的不同基本URL?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1068668.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存