在 11ty 标题中使用日期

Use a date in 11ty title

我有一个页面,我想在其中使用日期作为标题。我看到永久链接允许您使用该数据,但是,我不能在我的标题中使用日期。有没有办法在 Eleventy 中做到这一点?

---
title: "{{date}}"
date: 2020-10-10
---

标题中的这个returns{{date}}

Eleventy 目前支持对 permalink 字段使用数据变量和模板语法 ,但不支持任何其他 frontmatter 字段:

permalink: Change the output target of the current template. Normally, you cannot use template syntax to reference other variables in your data, but permalink is an exception. Read more about Permalinks.

Source. See also: Use data variables in Permalink.

但是,如果您使用 Computed Data,您 可以 使用模板字符串和数据变量。这样的事情应该有效:

---
eleventyComputed:
  title: "{{ date }}"
---

参见 Using a template string. Alternatively, you can do the same thing with JavaScript (if you need more control over the date format, for example). If you want to derive your title from date for all pages in a specific directory or of a specific layout template, you can also use directory data files or layout front matter