将Eleventy配置为不使用目录进行输出?
是否有可能以某种方式为 Eleventy 进行常规配置,以便输入文件夹中的“my_file.html”与 _site 文件夹中的“my_file.html”一样,而不是“/my_file/index.html”?
我知道我可以使用永久链接逐个文件地进行操作。但如果可能的话,我希望它为整个站点配置。
回答
不幸的是,由于不鼓励这种行为,因此没有简单的配置选项来禁用目录输出。
但是,由于permalink是数据级联的一部分,您可以设置全局默认值,并结合filePathStem计算数据,您可以将输出设置为.html文件。
要设置permalink使用全局数据文件,请将permalink.js文件添加到全局_data目录。
// _data/permalink.js
module.exports = '/{{ page.filePathStem }}.html'
v1.0.0 中还有一个配置全局数据选项即将推出。我不确定它是否会处理{{ page.filePathStep }}预处理,但如果可以,那也可能是一个选项,特别是因为它将在配置文件中保留与配置相关的内容。
- Great answer! Just a big warning that `permalink` strings will be processed to the syntax of the template file, so using a string globally might be a bit iffy. Should be safer to use a function instead.