jekyll / css 无法在 github 页面上运行,但可以在 localhost:3000 上运行

Col*_*ain 2 jekyll github-pages

我是 Github 的新手,我 \xe2\x80\x99 一直在尝试在 Github 页面上部署我的博客(从kimfucious分叉)。我尝试使用 Surge 来部署它,并且成功了。当我将其上传到 Github 时,它说 CSS 没有被应用。

\n

这就是现在的样子

\n

这是错误

\n

我\xe2\x80\x99m 显然做错了什么。但我无法弄清楚\xe2\x80\x99。

\n

这是我的仓库: https: //github.com/Colawithrain/Collin_Blog

\n

这是 Github 页面链接: https: //colawithrain.github.io/Collin_Blog/

\n

预先感谢您的任何指点。

\n

科林

\n

Ros*_*oss 5

这有点令人困惑,因为它可能在本地工作(您不需要baseurl)。这是 Jekyll 与 GitHub Pages 结合使用时最常见的错误之一。以下是运行情况:

您正在尝试加载:

https://colawithrain.github.io/assets/css/main.css
Run Code Online (Sandbox Code Playgroud)

但是,CSS 文件的服务位置为:

https://colawithrain.github.io/Collin_Blog/assets/css/main.css
Run Code Online (Sandbox Code Playgroud)

您目前正在_includes/head.html通过以下方式请求此信息:

<link rel="stylesheet" href="/assets/css/main.css">
Run Code Online (Sandbox Code Playgroud)

通过将其更改为以下内容来修复此问题:

<link rel="stylesheet" href="{{ site.baseurl }}/assets/css/main.css">
Run Code Online (Sandbox Code Playgroud)

然后将其设置在您的_config.yml

baseurl: /Collin_Blog
Run Code Online (Sandbox Code Playgroud)