问题描述
我正在使用Jekyll
开发一个静态站点,并将其部署在github pages
上.我在配置文件中使用baseurl时遇到问题.这是我的_config.yml
的摘录:
baseurl: "/blog"
url: "http://remidoolaeghe.github.io"
在 http://localhost:4000/blog/本地运行时,一切都很好.找到html页面,将资源(图像,css,js)加载并应用到页面上.
一旦部署在Github Pages
上,我希望该站点位于: http://remidoolaeghe. github.io/blog 但是实际的URL是 http://remidoolaeghe.github.io .
Github Pages
上的Jekyll
似乎未使用baseurl. HTML页面不在预期的URL,也没有任何资源(css,图像等).浏览器不会加载任何基于baseurl的内容,如您在此处看到的:
我已经检查了使用过的Jekyll version
.我使用的是Github Pages
(2.4.0).
我错过了什么吗?
可以在此处找到我的Github
repo.
重定向到/blog
的另一种方法是:
1.从
重定向GitHub Pages GitHub页面允许使用redirect-from
Jekyll插件,如此处.您可以使用他们的插件并从那里重定向.尽管它是为防止旧链接进入404而构建的,但鉴于用例,这可能并不是您想要的.
2.在根目录index.html
中手动添加元刷新标记.
<META http-equiv="refresh" content="0;URL=/blog/">
您需要在<head> </head>
中使用该标签.这会将告诉您根URL的任何请求指向存储在/blog/
的index.html
.这是一种快速的方法,类似于.htaccess
重写完成,除了GitHub Pages出于安全原因不支持.htaccess.那时,还要检查您是否获得了404
的某些资源,并相应地更新了它们的路径,也许在site.baseurl
的帮助下,如另一个答案所解释. baseurl
不是您认为的.请参阅这篇有关Parkurl变量的帕克帖子./p>
简而言之,我认为您最好的选择是使用第二种方法,而无需创建gh-pages blog
存储库并将站点移到那里.实际上,如果您确实转移到单独的博客存储库,这可能会使事情变得复杂,那么您仍然需要重定向http://remidoolaeghe.github.io
指向http://remidoolaeghe.github.io/blog
或其他访问http://remidoolaeghe.github.io
的人,而不是/blog
链接仅获得空白页.
I am developing a static site using Jekyll
, to be deployed on github pages
. I am facing issues using the baseurl in the configuration file. Here is an extract of my _config.yml
:
baseurl: "/blog"
url: "http://remidoolaeghe.github.io"
When ran locally at http://localhost:4000/blog/, everything is fine. The html pages are found, the resources (images, css, js) are loaded and applied on the pages.
Once deployed on Github Pages
, I would expect to have the site available at: http://remidoolaeghe.github.io/blogBut the actual URL is http://remidoolaeghe.github.io.
It seems the baseurl is not used by the Jekyll
on Github Pages
. The HTML pages are not at the expected URLs, neither any resources is (css, images, etc). Nothing based on baseurl is loaded by the browser, as you can see here:
I have checked the used Jekyll version
. I use the same as Github Pages
(2.4.0).
Have I missed something?
My Github
repo can be found here.
Another alternative to redirecting to /blog
is:
1. GitHub Pages Redirect from
GitHub pages allow for the redirect-from
Jekyll plugin as mentioned here. You could use their plugin and redirect from there. Although as it's built for preventing old links from going to 404, this might not be what you want given your use-case.
2. Manually have meta refresh tag in your root index.html
.
<META http-equiv="refresh" content="0;URL=/blog/">
You'll want that tag in a <head> </head>
. This will tell the any request to your root url point to the index.html
stored at /blog/
. This is a fast way to doing it, similar to how .htaccess
rewrites are done, except GitHub Pages doesn't support .htaccess for security reasons. At that point also check if you're getting 404
s for some resources and update their paths accordingly, maybe with the help of site.baseurl
, as another answer explains. baseurl
is not what you think it does. See this post by Parker about the baseurl variable.
In short,I think your best option is to use the second one, short of creating a gh-pages blog
repository and moving your site there. In fact, if you did move to a a separate blog repo which might make things complicated, you still need to redirect http://remidoolaeghe.github.io
to point to http://remidoolaeghe.github.io/blog
or else people who visit http://remidoolaeghe.github.io
and not the /blog
link get a blank page only.
这篇关于Jekyll中的localhost和github页面之间的Baseurl行为不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!