【问题标题】:Jekyll include looking in wrong directory permalinkJekyll 包括查找错误的目录
【发布时间】:2015-02-09 00:21:31
【问题描述】:

我有一个 Jekyll 站点,在根目录中有一些帖子和一些页面。

如果我导航到根目录中的页面,例如 localhost:4000/index.html _includes 目录中的所有文件使用加载没有问题:

{% include head.html %}

如果我随后使用 config.yml 中定义的永久链接格式访问帖子:

permalink: /:categories/:title
localhost:4000/blogpost/first-post

包含文件未加载。在 Firebug 中查看标头中的 CSS 文件,它会给出一个错误,即该文件未找到并且正在目录中查找:

/blogpost/first-post/css/boostrap.min.css

如果我在 YAML 中给帖子一个永久链接:

permalink: /first-post.html

一切正常。

当使用永久链接进行导航时,如何设置包含以在我的页面中找到正确的文件?

【问题讨论】:

  • 您的head.html 是否包含<link>css/bootstrap.min.css?将其更改为/css/bootstrap.min.css
  • 解决了,谢谢!

标签: css yaml jekyll


【解决方案1】:

Includesassets 是两个不同的东西。

Includes 是通常存储在_includes 中的部分。如果include anyfile.html 在 index.html 中工作,它可以在任何其他页面或帖子中工作。

assets 像 js、css 或图像一样由 html 按照路径加载。最好使用相对于站点根目录的路径。这就是 Jekyll 如此称呼资产的原因:

<link rel="stylesheet" href="{{ "/css/main.css" | prepend: site.baseurl }}">

因此,如果您的网站通过http://localhost/any/path 到达,您的_config.yml 看起来像这样:

url: http://localhost
baseurl: /any/path

然后,资产不再有问题!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-19
    • 2020-04-28
    • 2015-08-25
    • 1970-01-01
    • 2018-12-15
    • 2017-01-07
    • 1970-01-01
    相关资源
    最近更新 更多