【问题标题】:Eleventy is not adding an html suffix to index files generated from a nested index.md fileEleventy 没有为从嵌套 index.md 文件生成的索引文件添加 html 后缀
【发布时间】:2020-12-18 11:15:08
【问题描述】:

Eleventy 不会将 html 后缀添加到从嵌套 index.md 文件生成的索引文件中。

例如,这是一个包含我的源内容的示例目录结构...

|
+- /src (input dir)
    |
    +- post
    |   |
    |   +- my-cool-post
    |       |
    |       +- /images
    |       |
    |       +- index.md
    |
    +- index.md
    |
    +- about.md

当我运行命令npx eleventy 时,我得到以下输出...

|
+- /public (output dir)
    |
    +- post
    |   |
    |   +- my-cool-post
    |       |
    |       +- /images
    |       |
    |       +- index <---- NOTE there is no ".html" suffix on this file
    |
    +- index.html <----- this file is ok however
    |
    +- about.html <----- and so is this file

这就是我的.eleventy.js 配置文件设置..

// Data Extensions
const yaml = require("js-yaml");

module.exports = function (eleventyConfig) {

  eleventyConfig.addPassthroughCopy("_assets");
  eleventyConfig.addWatchTarget("./src/_sass/");
  eleventyConfig.addDataExtension("yaml", contents => yaml.safeLoad(contents));
  eleventyConfig.setTemplateFormats([
    "md",
    "css",
    "jpg",
    "png",
    "webp",
    "svg",
    "html"
  ]);
  return {
    jsDataFileSuffix: ".11ty",
    dataTemplateEngine: "njk",
    htmlTemplateEngine: "njk",
    markdownTemplateEngine: "njk",
    passthroughFileCopy: true,
    dir: {
      input: "src",
      data: "_data",
      includes: "_includes",
      layouts: "_layouts",
      output: "public"
    }
  }
}

如果没有*.html 后缀,url http://../post/my-cool-post 会返回 404 错误。如果我手动添加*.html 后缀,那么它可以工作。

知道我的设置有什么问题吗?

【问题讨论】:

    标签: eleventy ssg


    【解决方案1】:

    我发现了问题所在。在上面的示例中,/src/post/post.yaml 中有一个文件具有以下值:

    permalink: "{{ page.filePathStem }}"
    

    我有这个的原因是创建一个别名permalink,我可以在我的模板中使用它,而不必输入{{ page.filePathStem }}。事实证明,permalink 是一个保留属性,显然对渲染输出有影响。从文件中删除行修复了问题。

    【讨论】:

      猜你喜欢
      • 2012-12-04
      • 1970-01-01
      • 2018-06-10
      • 2019-06-16
      • 1970-01-01
      • 1970-01-01
      • 2018-06-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多