gpt4 book ai didi

css - Jekyll 包括查找错误的目录永久链接

转载 作者:行者123 更新时间:2023-11-28 17:25:07 25 4
gpt4 key购买 nike

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

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

{% include head.html %}

如果我然后使用 config.yml 中定义的永久链接格式转到帖子:

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

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

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

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

permalink: /first-post.html

一切正常。

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

最佳答案

Includesassets 是两个不同的东西。

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

assets,如 js、css 或图像,由 html 按照路径加载。最好使用相对于站点根目录的路径。这就是为什么 Jekyll 会这样调用 Assets :

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

因此,如果您的网站位于 http://localhost/any/path,您的 _config.yml 如下所示:

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

然后, Assets 就再也没有问题了!

关于css - Jekyll 包括查找错误的目录永久链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27407232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com