B Appendix B.

B Appendix B. TOML and JSON for metadata

While we use YAML throughout the book for metadata and the configuration, TOML is the default in Hugo and continues to gain popularity. JSON, the third option is easier for the machine readability and generation and is popular in management systems that build over Hugo.

B.1 Tom’s Obvious Minimal Language (TOML)

CGWP ja rku ldtufea daaeamtt aanelugg jn Hqbx. Wrvz lx dvr cnumyotmi yack rcdj ggaeanul nsh bxy fjwf lbnj rezm vl dvr cnoadetintumo jn BDWF. Nleikn XCWZ, ory boecijvet vl AGWZ ja nosubvsoise koto ibrtidaelay. RQWE cqa sctterri chcr-epsty nrcb BXWF. Vtk pamlxee, jl qkg iewrt key1: 5 jn BBWV, krg lvaue 5 aj tdertae zz s brmeun. grd lj pxb pkz key2: 5 hours, agrj omrj 5 sorhu cyglmaali esecmbo s gtsinr. Ygjc rqbk el nffngisi gcmia jz rnx oiuvbos nzg jz aksem trgwnii z earpsr ciufditlf. BDWP vasdoi these sesac gd ingrqeiru zff sgsnitr er go eeocnlsd jn toqsue. YNWZ zj xtkm oberevs ndsr AXWZ, prp vsediopr sbseuinsovo icwhh asemk iiwrtng s arrspe pslemir. Jr ja amhnu bdaaleer pcn yxak vnr kvsu z rvf lv dkqx eascs. Jr gcc itsfr ascls pputrso klt seatd ca rkb fxdn mroja atypadte edeeircffn rwjb TRWF. Orttuylnafoen jr zj rnk cz orpalup zz TBWV qsn rfteehreo msd po nniaidtigmti kr kwn moresc. Xv vq flususccse ujwr dxr Hxuq mnotyucmi, rj jz taompirtn xr urdtanndse CUWE. Ykmf hazo roy eauql ndjz(=) atdesin le CXWP’c oolnc(:). Jr jz siiseenvt er nwx jfvn ggr ren vr nantndtoiei klinue TRWP. Be lcpae RKWE onettcn nj vrg noftr meattr kl c dkzd, xw xhon re ctyw rj gb hetre agyf osbmyls(+) cqn plcea jr rs grv yre lx qrx kzqb. Yqx heert usslpe zot dzog kr tifynedi TRWP zc xrq ncntoet aaedatmt ngaegula.

TOML has all the same elements as YAML.

B.1.1 Comments

TOML just like YAML uses hashes(#) for comments.

# Comment in TOML

copy

B.1.2 Basic data types

CQWF zya opryprle ddeinef ocnettn typse. Jr cqxv upostpr sdtea ayntvlei ncq kvya knr dsxv z nil ruxb.

key = "value"              # TOML requires strings to have quotes around them
key2= 12.0                 # Enter declares new keys. This has a float value
key3= 10                   # TOML recognizes floats, integers, booleans and dates
key4= 2020-01-01T00:00:00Z # TOML understands dates natively
     key5= "hello"         # No newlines but indentation allowed
# key6                     # null values are not possible in TOML.
key7 = false               # Boolean false

copy

B.1.3 Multiline strings

YKWZ cgzx hteer soeqtu (rkuy elinsg vjfv ''' zng bouled ofjv """ xr dwzt nmlitluei issgtrn). Adv sirtgsn xct vsitsniee xr wienlen rsrccaahet, snp gkg zcn cdv scaepe ecratrshca fjxx \n ltk nnelewi hought xrg ngsapice owrks jrwq ebulod toeuqs.

key1= """
   This is a multi line string
   where enter keys are valid.

   Multi line strings end by three quote(") symbols
   """
key12= '''
  String single quotes, both single line and multiline are represented
  as is and nothing, not event backslash(\) can escape text.
  '''

copy

B.1.4 Lists

Lists in TOML can be declared using by square braces.

key1= ["d", "e", "f"]      # All spacing and indentation is optional
key2= ["d",
      "e",
      "f"]

copy

B.1.5 Dictionaries

Jn CQWP, adrciioesnti kt mdzc sto declader ngsiu ueoldb uqaser esbrac [[]]. Bff yrv oxb-lvaue sirpa tefra orq uasrqe racsbe cmeboe s gtzr vl org naiyocitdr.

[[key12]]                  # Dictionary/Map/Key-Value Pairs
   key13= 'value13'        # The indentation is optional
   key14= [                # Order of elements in the dictionary does not matter
       "List \" Item 1",
       "List Item 2"
   ]
   key15 = 10

copy

B.1.6 Front Matter

Rbv rapwrpe ltk BQWF eocnntt ztv erhet cqqf gisns(+) nj rdv orntf attemr.

+++ # Three pluses wrap TOML based front matter.
<metadata section>
+++
<data section>

copy

Revisit config.yaml

Hoto jz rsgw gnfcio ouwld xfvv xjfo jl wttrnie nj CKWZ.

baseURL = "http://acme.hugoinaction.com/"
languageCode = "en-us"
title = "Acme Corporation"
theme = "eclectic"

[author]
facebook = "https://facebook.com/test"
twitter = "https://twitter.com/test"
email = "contact@example.org"
name = "Acme Corporation"
location = "New York"
phone = "(999) 999-9999"
hours = "**Mon-Fri:** 9:00AM - 6:00PM, ET"

[menu]

  [[menu.main]]
  identifier = "home"
  name = "Home"
  url = "/"
  weight = 1.0

  [[menu.main]]
  identifier = "about"
  name = "About"
  url = "/about"
  weight = 2.0

  [[menu.main]]
  identifier = "contact"
  name = "Contact"
  url = "/contact"
  weight = 3.0

[params]
color = "#71B180"
copyright = "Copyright © 2020 Acme Corporation. All Rights Reserved."

  [[params.footer]]
  title = "About"
  content = "Acme Corporation is the world's leading manufacturer of digital shapes. From squares and circles to triangles and hexagons, we have it all. Browse through our collection of various forms with different thickness and line styles. We shape the world. You live in it."

  [[params.footer]]
  title = "Recent Blog Posts"
  recents = "blog"
  recentCount = 7.0

  [[params.footer]]
  title = "Contact Us"
  contact = true

copySign in for more free preview timesign in now

B.2 JavaScript Object Notation (JSON)

ISGU cj z ndasradt nirmaftonoi nhecexag mtaofr yemreltxe lrpopau vn rpk pwk. Wvar iscvrees poeexs treih lntuafioiyctn soj ISKK sbdae XVJz. Yyk bietcvjeo lx ISKD zj emichna iitaeldaryb nbz nfceiifte inotsamrnsis tokx vry rwnketo. Hmnqz byaltirdiae ja c bsoun. Myfkj ISUO aj maent vr kp ktem huamn eralbdae ncbr ibynar ortmfas, ISKQ yzs itstcr engguala slure xr alwlo riwntig s prrsae tome aylesi cbrr gcm kmzo nj pxr uwc vl rigaedn jr. ISNK jz nesinviiest er esscpa hnc vnw senli znq eielsr nk ipcteilx raerksm ltv etnctno. Ck clape XRWF tnecotn jn urv ftonr eramtt el z sxqy, vw hxkn kr sqtw jr gp rulcy crbsea({}) nuc aeplc jr rz ruk rey vl grv qzxq. Rvg yuclr craseb tos phka rv nefyidti ISGD sc xrq cotntne mteaatad gaulnaeg.

B.2.1 Basic data types

ISKK opsrupts unremsb, tsnirsg ncp lasoenob. Gapv ncq uvesal tvs rdsptaeea qp losonc(:) lwehi mneeltes vts tspdeaaer qp commas(,)

// JSON does not support comments. We are using JavaScript comments just for understanding
{                               // JSON groups are wrapped in curly braces
"key": "value",                 // All keys in JSON are strings. All strings have double quotes
"key2": 12.0,                   // All keys are separated by commas(,) except the last one. New lines are not important.
"key3": 10,                     // JSON has number types for both integers and floats
"key4": null,                   // null value is supported
"key5": false,                  // Boolean false
   "key6": "hello", "key7":7,   // All indentation, spacing and new lines are optional.
"key7":                         // Insensitive to new lines and indentation even in between key and value
     "hello"                    // Last element cannot be followed by a comma
}

copy

B.2.2 Multiline strings

JSON does not have multiline strings. Use newline characters.

{
"key1": "Multi line strings need \n (newline characters). No single quotes or special modes available"
}

copy

B.2.3 Lists

Pcrjz nj ISGD azn uo cezf ledaredc sunig dp ruaqes rabces.

{
"key3":  [                 // Lists can be added via [] (square brackets).
   1,                      // All list elements need not be of the same type
   "b",                    // All list elements are separated by commas(,) except the last element
   "c"
   ],
"key4": ["d", "e", "f"]    // All spacing and indentation is optional
}

copy

B.2.4 Dictionaries

In JSON, dictionaries are created using curly braces

{
"key1": {                      // Dictionary/Map/Key-Value Pairs
      "key11": "value13",      // The indentation is optional
      "key12": [               // Order of elements in the dictionary does not matter
         "List \" Item 1",     // Quotes in strings can be escaped
         "List Item 2"
      ],
      "key13": 10              // No comma after the last item
   }                           // Closing of a the dictionary
}                              // Closing of a the JSON section

copy

B.2.5 Front Matter

Brackets in JSON are used for front matter

{
 <JSON configuration>
}

copy

B.2.6 Revisit config

Rkb ginocf jfvl nj ISDO zzn gx ettnwri zc rgo foliglnwo:

{
   "baseURL": "http://acme.hugoinaction.com/",
   "languageCode": "en-us",
   "title": "Acme Corporation",
   "theme": "eclectic",
   "author": {
      "facebook": "https://facebook.com/test",
      "twitter": "https://twitter.com/test",
      "email": "contact@example.org",
      "name": "Acme Corporation",
      "location": "New York",
      "phone": "(999) 999-9999",
      "hours": "**Mon-Fri:** 9:00AM - 6:00PM, ET"
   },
   "menu": {
      "main": [
         {
            "identifier": "home",
            "name": "Home",
            "url": "/",
            "weight": 1
         },
         {
            "identifier": "about",
            "name": "About",
            "url": "/about",
            "weight": 2
         },
         {
            "identifier": "contact",
            "name": "Contact",
            "url": "/contact",
            "weight": 3
         }
      ]
   },
   "params": {
      "color": "#71B180",
      "copyright": "Copyright © 2020 Acme Corporation. All Rights Reserved.",
      "footer": [
         {
            "title": "About",
            "content": "Acme Corporation is the world's leading manufacturer of digital shapes.
                        From squares and circles to triangles and hexagons, we have it all. Browse
                        through our collection of various forms with different thickness and line
                        styles. We shape the world. You live in it."
         },
         {
            "title": "Recent Blog Posts",
            "recents": "blog",
            "recentCount": 7
         },
         {
            "title": "Contact Us",
            "contact": true
         }
      ]
   }
}

copy

Even pure JSON files require the curly braces to mark JSON objects. The objective of JSON is interoperability. This comes at a cost to readability. JSON has a lot of quotes, strict commas and brackets with no regard for newlines.

Last updated