gpt4 book ai didi

permalinks - Eleventy 中没有固定链接

转载 作者:行者123 更新时间:2023-12-02 02:53:37 25 4
gpt4 key购买 nike

我正在从 Jekyll 迁移到 Eleventy,之前我的博文链接具有这种样式的永久链接:/: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 中配置它? official page在 11ty 文档上说它采用文件夹的名称,在本例中为 posts

我想要这个 /:title/ 用于我所有的 Markdown 文件。我无法在所有文件中手动设置永久链接。有没有办法对整个 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 thefollowing:

---
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"
}

关于permalinks - Eleventy 中没有固定链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61549284/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com