我有一个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
一切正常。
使用永久链接导航时,如何设置包含以在页面中找到正确的文件?
Includes
和assets
是两个不同的东西。
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
然后,资产不再有问题!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句