在外部文件上设置基目录玉、咕噜声、指南针



我正在使用玉咕噜声和指南针来生成一个站点,而不是在玉文件中键入文件的正确路径,例如:

link(href='../../../../stylesheets/sections/pdp.css'

想知道我有一种方法可以使用类似/stylesheets/section.pdp 的东西.css

所以我不必每次都写正确的路径。

谢谢!

编辑:

配置.rb

http_path = "/"
css_dir = "stylesheets"
sass_dir = "scss"
images_dir = "assets/images"
javascripts_dir = "scripts"
#output_style = :compressed
relative_assets=true
line_comments = false

在您的示例中,pug 没有在 ../../../../stylesheets/sections/pdp.css 读取文件。它将该字符串输出为 link HTML 标记的 href 属性的值,如下所示:

<link href="../../../../stylesheets/sections/pdp.css" />

因此,这些路径不是相对于您的views目录:它们是相对于浏览器获取的路径。

这些href字段使用绝对 URL 而不是相对 URL 可能会让您受益匪浅。喜欢这个:

link(href='/stylesheets/sections/pdp.css')

下面的代码是等效的,但排除了 css 目录的路径,这可能对其他标签有用:

- var cssDir = '/stylesheets';
link(href= cssDir + '/sections/pdp.css')

最新更新