Github Pages 上的 Jekyll 不渲染 CSS

标签 jekyll github-pages

我一直在试验 Jekyll 使用 Octopress 进行部署。我已经让它在本地主机上完美运行,但是由于某种原因,当站点在 Github Pages 上加载时,CSS 没有加载。我很感激任何帮助理解原因。

当我在 Github Pages url 查看加载的站点时,它显示 main.css 的 404 错误.发起人列(使用 Chrome 中的开发人员工具顺便说一句)表明这来自 index.html 文件,在 HTML 标题中的行:

  <link rel="stylesheet" href="/css/main.css">

树为_site我本地机器上的目录是:
.
├── 2015
│   └── 11
│       └── 09
│           ├── another-jekyll-blog.html
│           ├── fifth-time-is-the-charm.html
│           └── jekyll-and-octopress-is-this-thing-on.html
├── about
│   └── index.html
├── css
│   └── main.css
├── feed.xml
├── index.html
└── jekyll
    └── update
        └── 2015
            └── 11
                └── 09
                    └── welcome-to-jekyll.html

在站点被推送后,这棵树在 Github 存储库中完全匹配(我使用 jekyll build 后跟 octopress deploy)。

当我查看开发人员工具中的 Sources 选项卡时,对于已部署的站点,树显示为:
[USER].github.io
|-css
|   |-main.css
|
|-octo-5
|   |-(index)

但是当我在本地主机上查看站点时,站点树是:
localhost:4000
|-css
|   |-main.css
|
|-(index)

这个问题显然与在 Github Pages 上引用 main.css 文件的方式有关。我假设索引文件中样式表的链接不起作用,因为 main.css 不在相对路径中 /css/main.css正如预期的那样。它可以在本地运行,但不能在 Github Pages 站点上运行。但我不明白为什么,因为站点树看起来是正确的,没有从 Jekyll 默认值修改,并且在本地和远程都是一样的。

好的措施,包括 _config.yml下面的文件。尽管我添加了一些 Octopress 设置,但它与安装时的默认设置基本没有变化:
# Site settings
title: Test Site
email: your-email@domain.com
description: > # this means to ignore newlines until "baseurl:"
  Site description here...
baseurl: "" # the subpath of your site, e.g. /blog
url: "http://yourdomain.com" 
twitter_username: jekyllrb

## --- Octopress defaults --- ##
# Default extensions for new posts and pages
post_ext: markdown
page_ext: html

# Default templates for posts and pages, found in _templates/
post_layout: post
page_layout: page

# Format titles with titlecase?
titlecase: true

# Change default template file (in _templates/)
post_template: post
page_template: page
draft_template: draft

作为引用,该存储库可在以下位置公开获取:https://github.com/bg-scro/octo-5

最佳答案

我正在使用 jekyll 和 github 的个人网站生成器。将以下代码添加到下面的 _config.yml 文件中解决了我的 css 未在生产中呈现的问题。不完全确定为什么。想要一个解释。 :)

baseurl: /PROJECT
url: http://USERNAME.github.io

repo :https://github.com/kaeland/kaeland.github.io

关于Github Pages 上的 Jekyll 不渲染 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33634520/

相关文章:

javascript - 无法将外部 JavaScript 与 Jekyll 链接

html - Jekyll 博客文章未显示在 github 页面上

html - 没有为 GitHub 页面加载 CSS

jekyll - 有什么创造性的方法可以克服 jekyll 的默认 'reverse chronological order' 列表?

ruby - Jekyll 构建和服务无法在 Ubuntu (WSL) 上运行

jekyll - 如何将变量从页面传递到 Liquid 中的布局?

javascript - 如何在基本 Vue html 文件中使用 Vue 组件 (.udm.js)?

git - 为什么调用 git branch --unset-upstream 来修复?

github-pages - 如何在 Github Pages 上修改已部署的 create-react-app?

Github:镜像 gh-pages 到 master