JimYuan's Blog

Sharing the things I learned

0%

YAML_Intro

Foreword

I went a long long walk today, approximately 21km and took me 6.7 hours. The weather today was just so great. Recently, I noticed that if the article I posted only has the techicial contents, that might be a bit boring. The whole keep posting thing is for me to be motivated, so I decided that I need to write down some thoughts ahead or behind the article, to make it more human.

What’s my thoughts about YAML before learning it.

I have had much knowledge about yaml before I tried to post on github Page. I am currently using the hexo framework, organizing my blogs, and inside the folder, there’s one .yaml file owns a lot of settings we can play around.

Lecture

https://www.youtube.com/watch?v=cdLNKUoMc6c&t=2s

YAML is a data_serialization language, which means it’s basically just used to store information about different things

  • We can use yaml to define key-value pairs.
  • Very similar to JSON, but YAML focusing on readability and user friendiness

Format

  • .yml
  • .yaml

comment in YAML

1
# This won't be executed in yaml

key-value example in yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
person:
name: &name "mike"
occupation: 'programmer'
age: 23
gpa: 3.5
fav_num: 1e+10
male: true
birthday: 1994-02-06 14:33:22 #ISO 8601
flaws: null
hobbies:
- hiking
- movies
- riding bike
movies: ["Dark Knight", "Good Will Hunting"]
friends:
- name: "Steph"
age: 22
- {name: "Adam", age: 22}
-
name: "joe"
age: 23
desciption: >
Coming soon, Aeron in Onyx, made with ocean-bound plastic. Same design. Same comfort. Now more sustainable.
signature: |
Mike
Giraffe Academy
email - giraffeacademy@gmail.com
id: *name #"mike"

base: &base
var1: value1

foo:
<<: *base # var1: value1
var2: value2


The way that we can define scope inside of yaml is with indentation(tab).

  • With > before a bunch of text, yaml will render the text in a single line.
  • With |, this will preserve the format correctly.
  • & as an anchor mark, * to call that anchor value
  • & anchor mark can also anchor a entire key-value, the example &base
  • !!float can force int to float, changing the type