十一怎么有相对路径?

jos*_*t21 7 javascript static-site eleventy

我目前正在做一个11ty项目并且非常喜欢它。但是我在部署输出时遇到了链接问题。我想将它部署到不同服务器上的 2 个不同位置。其中一个位置位于根目录中,另一个位于子文件夹中。

输出中是否可以有相对链接?

我已经尝试过pathPrefix,但要么我没有正确使用它,要么它没有给我我正在寻找的结果。

.eleventy.js

module.exports = eleventyConfig => {

    ...

    // Include our static assets
    eleventyConfig.addPassthroughCopy("images")

    return {
        pathPrefix: "/subfolder/",
        templateFormats: ["md", "njk"],
        markdownTemplateEngine: 'njk',
        htmlTemplateEngine: 'njk',
        passthroughFileCopy: true,

        dir: {
            input: 'site',
            output: 'dist',
            includes: 'includes',
            data: 'globals',
        }
    }

}

Run Code Online (Sandbox Code Playgroud)

当我运行时eleventy --config=eleventy.config.js --serve,会生成一个名为 的附加文件夹_eleventy_redirect,其中包括一个index.html文件:

<!doctype html>
  <meta http-equiv="refresh" content="0; url=/subfolder/">
  <title>Browsersync pathPrefix Redirect</title>
  <a href="/subfolder/">Go to /subfolder/</a>

Run Code Online (Sandbox Code Playgroud)

当我运行eleventy --config=eleventy.config.js(没有--serve)时,该文件夹不存在。但是,无论哪种方式,所有链接都是绝对链接(例如,主页href="/"),并且该站点在服务器上不起作用。

有没有办法有两种相对链接(比如首页href="./"根index.html,然后href="../"在子页面),或至少包含的网址(例如,子文件夹主页href="./subfolder/")?

jos*_*t21 2

不完全是我想要的,但它有助于解决我问题的某些部分。url 过滤器
标准化绝对路径,例如

href="{{ "/" | url }}"
Run Code Online (Sandbox Code Playgroud)

更多细节请参见111 github 。