Jekyll YAML循环参考

问题描述:

我有一个包含两个页面的jekyll项目,每个页面均由相互引用的YAML映射支持.例如:

I have a jekyll project with two pages, each backed by YAML maps that both reference each other. For example:

a: &a
  name: "Ay"
  parents: []
  children: [*b]

b: &b 
  name: "Bee"
  parents: [*a]
  children: []

Vanilla YAML似乎不支持在定义别名/锚之前使用别名/锚,这会使该策略无效.有什么办法,也许使用液体富让我生成列举条目的父母和孩子的页面?

Vanilla YAML seems not to support using an alias/anchor before its been defined, which invalidates this strategy. Is there any way, perhaps using liquid-fu that would let me generate pages that enumerate an entry's parents and children?

您只需要在首次出现时提供该值:

You just need to give the value on first occurrence:

a: &a
  name: "Ay"
  parents: []
  children:
    - &b
      name: "Bee"
      parents: [*a]
      children: []
b: *b

alias/anchor构造是专门为该用例设计的.由于解析的YAML数据无法区分对象的锚定位置和引用的位置,因此这等同于您想要的对象.

The alias/anchor construct has been designed specifically for this use-case. Since the parsed YAML data does not distinguish the place where the object is anchored and the place where it is referenced, this is equivalent to what you want to have.