Jekyll/Liquid - 如何将大块文本添加到 YAML 前面的内容?

发布于 2024-11-25 03:24:13 字数 332 浏览 2 评论 0原文

我正在尝试在 Jekyll 中实现一个服务目录,其中每 20 或 30 个页面将包含一个 7x2 表。左列将包含标签,例如“概述”、“可用”等,而右列将包含一行和多个文本段落之间的内容。我希望用 Liquid 变量来表征右列,例如 {overview}、{availableTo}

我注意到 YAML 似乎对换行符非常挑剔,因此我必须在上输入这些段落及其标记一行可以持续几个屏幕宽度。这是一个问题,因为它很烦人,而且还因为我希望这些前端问题可以由技术用户但非 Webdev 用户编辑。有没有办法让前面的内容能够容忍中断?

或者,有没有一种方法可以使用 {content} 部分填充此表,而不必每次都将表重新编码到其中?

I'm trying to implement a service catalog in Jekyll, in which each of 20 or 30 pages will contain a 7x2 table. The left column will hold labels, e.g. Overview, Available To, etc, while the right column will hold between one line and several paragraphs of text. I was hoping to characterize the right column with Liquid variables, e.g. {overview}, {availableTo}

I've noticed that the YAML seems to be very picky about line breaks, and accordingly I've had to input these paragraphs and their markup on one line which can go on for several screen-widths. This is a problem because it's annoying, and also because I'd like these front-matters to be editable by technical but non-webdev users. Is there a way to have the front matter tolerate breaks?

Alternatively, is there a way that I could populate this table with the {content} section, without having to recode the table into it each time?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆沫 2024-12-02 03:24:13

多行字符串的 Yaml 语法是这个

body: |
  This is a multi-line string.
  "special" metacharacters may
  appear here. The extent of this string is
  indicated by indentation. 

注意第一行必须是一个空格,后跟 | 字符和新行。然后,您必须将文本比其父级缩进一级。

因此,您可以通过这种方式创建一个项目:

item1:
  overview: |
    overview text
    more overview text
  available_to: 2012-01-01
  foo: |
    foo text
    more foo text

在我看来,您也想按顺序排列您的项目。您可以为此使用 yaml 列表:

catalog:
  - id: item 1
    overview: |
      overview text
      more overview text
    available_to: 2012-01-01
    foo: |
      foo text
      more foo text
    ...
  - id: item2
    overview: <similar to above>

Yaml syntax for multi-line strings is this one:

body: |
  This is a multi-line string.
  "special" metacharacters may
  appear here. The extent of this string is
  indicated by indentation. 

Notice that the first line must be an space followed by the | character and a new line. Then you must indent the text one level more than its parent.

Consequently, you can create one item this way:

item1:
  overview: |
    overview text
    more overview text
  available_to: 2012-01-01
  foo: |
    foo text
    more foo text

It seems to me that you also want to arrange your items in order. You can employ a yaml list for that:

catalog:
  - id: item 1
    overview: |
      overview text
      more overview text
    available_to: 2012-01-01
    foo: |
      foo text
      more foo text
    ...
  - id: item2
    overview: <similar to above>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文