首页 文章

Jekyll包括查看错误的目录永久链接

提问于
浏览
1

我有一个Jekyll站点,其中包含一些帖子和根目录中的一些页面 .

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

{% include head.html %}

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

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

未加载包含文件 . 在 Headers 中的CSS文件中查看Firebug会出现错误,指出找不到文件并且正在查找目录:

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

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

permalink: /first-post.html

一切正常 .

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

1 回答

  • 1

    Includesassets 是两回事 .

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

    assets 像js,css或图像是由路径后的html加载的 . 它's better to use a path relative to the site root. That'为什么杰基尔称之为这样的资产:

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

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

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

    然后,没有资产问题!

相关问题