get
A helper method that provides convenient map-like query access for fetching (possibly nested) frontmatter values.
Imagine you have the following frontmatter declaration:
title: Title
data:
assets:
images:
- cat.png
- dog.png
font: Roboto
Content copied to clipboard
Once parsed into a FrontMatterElement, you can query it like so:
val fm: FrontMatterElement = ...
fm["title"] // returns listOf("Title")
fm["data.assets.images"] // returns listOf("cat.png", "dog.png")
fm["data.assets.images.1"] // returns listOf("dog.png")
fm["data.assets.font"] // returns listOf("Roboto")
fm["key-not-found"] // returns null
Content copied to clipboard
If you are sure that you are fetching a scalar value, you can use the single
method:
fm.getValue("title").single()
Content copied to clipboard
Note that querying a path to a map (e.g. fm["data.assets"]
for the case above) will return null and NOT an empty list, as a map is not a scalar nor a list of scalars. If you absolutely need to distinguish between these two cases, use the query method instead.