Eleventy 中没有固定链接

No permalink in Eleventy

我正在从 Jekyll 迁移到 Eleventy,之前我的博客 post 链接具有这种样式的永久链接:/:title/

What I want: https://example.com/my-blog-post/ for posts/my-blog-post.md

What I get: https://example.com/posts/my-blog-post/ for posts/my-blog-post.md

如何在 Eleventy 中进行配置? 11ty 文档上的 official page 表示它采用文件夹的名称,在本例中为 posts

我想要这个 /:title/ 用于我所有的降价文件。我无法在所有文件中手动设置永久链接。有没有办法对整个 posts 集合执行此操作?

我使用 this repo 作为基本主题。

所以在搜索了很多(不是文档)之后,我终于在 this article 中找到了解决方案。

在该部分的最后一部分,使用这个:

// posts.json (or whatever your collection name is)
{
   // ...
   "permalink": "/{{ title | slug }}/"
   // ...
}

摘录:

Using directory data to manage defaults

By default, Eleventy will maintain the structure of your content files when generating your site. In our case, that means /_basic-syntax/lists.md is generated as /_basic-syntax/lists/index.html. Like Jekyll, we can change where files are saved using the permalink property. For example, if we want the URL for this page to be /basic-syntax/lists.html we can add the following:

---
title: Lists
syntax-id: lists
api: "no"
permalink: /basic-syntax/lists.html
---

Again, this is probably not something we want to manage on a file-by-file basis but again, Eleventy has features that can help: directory data and permalink variables.

For example, to achieve the above for all content stored in the _basic-syntax folder, we can create a JSON file that shares the name of that folder and sits inside it, i.e. _basic-syntax/_basic-syntax.json and set our default values. For permalinks, we can use Liquid templating to construct our desired path:

{
   "layout": "syntax",
   "tag": "basic-syntax",
   "permalink": "basic-syntax/{{ title | slug }}.html"
}

您可以为每个页面或每个集合设置永久链接。假设您创建了一个 posts 文件夹,然后添加了一个 posts.11tydata.json 文件,其中包含为集合设置基本值的内容。

{
  "eleventyExcludeFromCollections": false,
  "layout": "post",
  "permalink": "post/{{ title }}/",
  "tags": [
    "posts"
  ]
}