Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jekyll YAML cyclic reference

Tags:

yaml

jekyll

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 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?

like image 944
user12341234 Avatar asked Sep 11 '26 05:09

user12341234


1 Answers

You just need to give the value on first occurrence:

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

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.

like image 136
flyx Avatar answered Sep 13 '26 20:09

flyx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!