wobsite.FrontMatter
type pub FrontMatter
A type storing the parsed front matter of a document.
Fields
title
let pub @title: String
The title of the page.
date
let pub @date: DateTime
The date at which the page is created.
Static methods
parse
Show source codeHide source code
fn pub static parse(string: String) -> Result[FrontMatter, FrontMatterError] {
let json = try Json.parse(io.Buffer.new(string)).map_error(fn (e) {
FrontMatterError.InvalidJson(e.to_string)
})
let title = match json.query.key('title').as_string {
case Some(v) -> v
case _ -> throw FrontMatterError.InvalidKey('title')
}
let date = match json.query.key('date').as_string {
case Some(v) -> {
match parse_date(v) {
case Some(v) -> v
case _ -> throw FrontMatterError.InvalidKey('date')
}
}
case _ -> DateTime.utc
}
Result.Ok(FrontMatter(title: title, date: date))
}
fn pub static parse(string: String) -> Result[FrontMatter, FrontMatterError]
Parses JSON front matter from a String
.