Jekyll/Liquid - 如何在YAML前端添加大块文本?

pat*_*jmc 51 yaml liquid jekyll

我正在尝试在Jekyll中实现一个服务目录,其中20或30页中的每一页都包含一个7x2表.左列将保留标签,例如Overview,Available To等,而右列将保持在一行和几段文本之间.我希望用液体变量来表征正确的列,例如{overview},{availableTo}

我注意到YAML似乎对换行非常挑剔,因此我不得不在一行上输入这些段落及其标记,这些行可以持续几个屏幕宽度.这是一个问题,因为它很烦人,也因为我希望技术但非webdev用户可以编辑这些前端内容.有没有办法让前面的事情容忍休息?

或者,是否有一种方法可以使用{content}部分填充此表,而无需每次都将表重新编入其中?

kik*_*ito 81

多行字符串的Yaml语法是这样的:

body: |
  This is a multi-line string.
  "special" metacharacters may
  appear here. The extent of this string is
  indicated by indentation. 
Run Code Online (Sandbox Code Playgroud)

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

因此,您可以这样创建一个项目:

item1:
  overview: |
    overview text
    more overview text
  available_to: 2012-01-01
  foo: |
    foo text
    more foo text
Run Code Online (Sandbox Code Playgroud)

在我看来,你也想按顺序安排你的物品.您可以使用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>
Run Code Online (Sandbox Code Playgroud)

我希望这有帮助!

  • FWIW,有[很多](http://stackoverflow.com/questions/3790454/in-yaml-how-do-i-break-a-string-over-multiple-lines/21699210#21699210)不同的多YAML支持的行字符串格式.在许多情况下,`>`比`|`更好,因为它不会在每行的末尾插入换行符. (3认同)