我有这样的文件head.pug
head
h2
a(href="") This is title
我的目录是:
contact
+ index.pug
pug
+ head.pug
index.pug
在我的主页和联系中,我使用index.pug
,我可以像这样包括head.pug
include pug/head.pug
and
include ../pug/head.pug
它会打印HTML
<head>
<h2><a href="">This is title</a></h2>
</head>
但在联系目录中,它应该打印这样的链接
<head>
<h2><a href="../">This is title</a></h2>
</head>
我能怎么做 ?
你可以在/
使用正斜杠href
。这应该适用于您关注链接到主页。
例:
head
h2
a(href="/") This is title
<head>
<h2><a href="/">This is title</a></h2>
</head>
对于非主页链接,我建议您为根保留一个全局变量,并存储要链接的文档的绝对路径。
示例:var TITLE_PATH = <project url here >+'public/someFolder/index.html';
然后,你的PUG代码变成了
head
h2
a(href=TITLE_PATH) This is title