在Git Pages上正确托管Jekyll网站 [英] Correctly hosting Jekyll website on Git Pages

查看:262
本文介绍了在Git Pages上正确托管Jekyll网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很绝望。我的任务是将使用 Jekyll 生成的静态网站部署到 GitHub页面,使用项目选项(而不是用户选项)。



不知何故,当我使用Jekyll检查我的机器中的网站时,一切都正常。但是一旦我部署到Git Pages,我的所有CSS文件就停止工作,每个链接都会导致404找不到错误。



我已经遵循了几个指南和教程,他们都失败了:





到目前为止,我总是创建存储库,分支机构,我总是推动一切。我不相信错误在部署中,但在某些地方。



我的回购可以在这里找到:





对于那些你想知道的,到目前为止,存储库只是一个教程的结果:
- AndrewMunssel教程



我还测试过其他教程,但是我总是遇到一个问题。我的代码错了吗我正在关注的教程过时和不正确吗?我应该怎么做?

解决方案

您网站上的所有内容都位于域外的子目录中,因此主要网站在此处访问



http://fl4m3ph03n1x.github.io/web-tutorials/



模板指向域的根目录,所以它试图从加载样式表http://fl4m3ph03n1x.github.io/assets 而不是他们所在的位置 http://fl4m3ph03n1x.github.io/web-tutorials/assets/ 同样的事情发生在你的帖子中。



您需要做的是在 _config.yml baseurl >

  baseurl:/ web-tutorials 

然后您需要修改模板,以便CSS和JS的路径使用以下约定

  {{site.baseurl}} / path / to / css.css 

链接

  {{site.baseurl}} {{post.url}} 

您还需要更新网站设置在 _config.yml


I am desperate.My mission is to deploy a static website generated using Jekyll into GitHub Pages, using the "Project" option (instead of the user option).

Somehow, when I use Jekyll to check the website in my machine, everything works fine. But once I deploy it to Git Pages, all my CSS files stop working, and every link leads to a 404 not found error.

I have followed several guides and tutorials but they all fail:

So far I always created the repositories, the branches and I always push everything. I do not believe the error is in the deployment, but in some place else.

My repo can be found here:

For those of you wondering, so far the repository is only the result of one tutorial: - AndrewMunssel tutorial

I have also tested other tutorials, but I always end up with a problem. Is my code wrong? Are the tutorials I am following outdated and incorrect? What should I do?

解决方案

Everything on your site is in a sub directory off of the domain so the main site is accessed here

http://fl4m3ph03n1x.github.io/web-tutorials/

The templates are pointing to directories on the root of the domain so it is trying to load your stylesheets from http://fl4m3ph03n1x.github.io/assets rather than where they are located http://fl4m3ph03n1x.github.io/web-tutorials/assets/ the same thing is happening for your posts.

What you need to do is set the baseurl in your _config.yml

baseurl: /web-tutorials

you then need to modify your templates so that the paths to CSS and JS use the following convention

{{ site.baseurl }}/path/to/css.css

and for post links

{{ site.baseurl }}{{ post.url }}

You also need to update the site setting in _config.yml

这篇关于在Git Pages上正确托管Jekyll网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆