Jekyll 不会将 CSS 应用于 GitHub 页面上的帖子

Jekyll doesn't apply CSS to posts on GitHub Pages

是的,我知道这个问题已经被问过很多次了,我已经应用了我能找到的所有解决方案,但我仍然遇到这个问题:

如果您访问我的 Jekyll 站点 (yasath.github.io), the homepage and the tags page in the navbar render the CSS perfectly and look beautiful. However, when I click on a post (like this one),CSS 完全无法呈现,我最终得到一个看起来很旧的白色背景,Times New Roman 文本页面!

我的 config.yml 文件具有正确的 URL(据我所知!),当我使用 Chrome 的开发人员工具查看这两个页面的源代码时,它们都导入了相同的内容CSS 文件正确。

希望有人能给我针对我网站的建议! This is the GitHub repo for the site, and again, here is the actual site.

<head> 部分中样式表的链接被写为相对链接。例如:

<link rel="stylesheet" href="assets/css/app.min.css">

当 URL 以 "assets" 之类的目录名称开头时,浏览器会查找相对于它现在显示的 URL 的目录。所以当你在 yasath.github.io 时,它会转到 yasath.github.io/assets/css/app.min.css... 但是当你在 https://yasath.github.io/2017/09/04/hello-jekyll.html 时,它会在 https://yasath.github.io/2017/09/04/hello-jekyll.html/assets/css/app.min.css 寻找样式表,当然不存在。

您想以 / 开始您的 URL。这告诉浏览器不是相对于它显示的页面,而是相对于网站的根目录。所以在你的头模板中使用:

<link rel="stylesheet" href="/assets/css/app.min.css">

...与所有其他样式表类似 URLs.