node.js - Eleventy 编程 API - 输入路径应该是什么样的?

我有一个 aws lambda 函数,它调用 eleventy.write() 或 eleventy.toJSON() 方法,但似乎无法使其工作。我尝试了不同的项目结构并设置了不同的路径,但它要么返回一个空数组,要么抛出以下错误 TemplateLayoutPathResolver directory does not exist for filename.njk: _includes 当我从终端运行 eleventy 命令时,它构建成功。这是我的 11ty 项目结构

project root folder
-- public (output of the eleventy build)
-- .eleventy.js
-- src (input for the eleventy build)
  |-- _data
  |-- _includes

我的 .eleventy.js 文件如下所示:

...
 return {
        dir:{
            input: 'src',
            output: 'public',
        },
    };

在进行 write() 调用的 lambda 函数项目中,我尝试设置相对于文件的输入路径,然后尝试将 11ty 根文件夹放在 .js 文件旁边并像 let eleventy = new Eleventy(".", "public") 一样实例化 eleventy这没有用,我还尝试获取 eleventy 根项目的内容并将其放在我正在调用 write() 的 .js 文件旁边。

还尝试像这样设置configPath

let eleventy = new Eleventy(".", "public", {
    configPath: "./.eleventy.js",
  });

但仍然无法正常工作。

eleventy 编程 API (https://www.11ty.dev/docs/programmatic/) 的文档非常薄,因此我们将不胜感激。

回答1

查看上面的文件列表,在 src 中,我看到的是 includes,而不是 _includes。你忘了下划线吗?

回答2

只需将您的输入文件夹设置为“src”

let eleventy = new Eleventy("src", "public");

相似文章

随机推荐

最新文章