Jekyll _post 不使用 css 当站点内置于 _site

Jekyll _post not using the css when the site is built into the _site

我在 _post 中的 post 在使用 bundle exec jekyll serve 时应用了 css。当我去构建 jekyll 站点时: bundle exec jekyll build; _post 中的 post 不再应用 css,即使在构建站点的 html 源中,它们具有相同的 <link rel="stylesheet" href="/assets/css/styles.css">

这里是文章_layout:

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://fonts.googleapis.com/css?family=Lato:100,300,400,700,900" 
rel="stylesheet">
    <title>{{ page.title }}</title>
    <link rel="stylesheet" href="/assets/css/styles.css">
    <link rel="shortcut icon" type="svg/svg" href="assets/svg/users-dmitri13.svg">
  </head>
  <body>
   {% include navigation.html %}
   {{ content }}
   {% include footer--articles.html %}
  </body>

如果我在<link rel="stylesheet" href="/assets/css/styles.css">中去掉开头/。 css会出现在建站的文章页面,但是post就找不到css.

post_layout:

---
layout: articles
---


<article class="article">
  <div class="header--large header--large--gradient">
      <div class="heading-primary--main-static header__text-box">
          <h1>{{ page.title }}</h1>
      </div>
  </div>

  <div class="article__content">
      <p>{{ page.date | date_to_string }} - {{ page.author }}</p>
      <div class="paragraph--big">
          {{ content }}
      </div>
  </div>

您应该使用 link 标签。 Jekyll 将在 _site 文件夹中为您生成正确的输出 URL。

<link rel="stylesheet" href="{% link /assets/css/styles.css %}">

Docs for the link tag.

当包含所有文件的文件夹是根文件夹时,<link rel="stylesheet" href="/assets/css/styles.css"> 有效。

使用 bundle exec jekyll serve 或托管在网络服务器上会使包含所有文件的文件夹成为根文件夹。 /assets/css/styles.css 中的开头 / 告诉 <link rel="stylesheet" href="/assets/css/styles.css"> 开始查找文件夹的根目录。