wobsite.Page
type pub Page
A page backed by a Markdown document.
Fields
front_matter
let pub @front_matter: FrontMatter
The JSON front matter.
url
let pub @url: String
The URL of the page.
source_path
let pub @source_path: Path
The path to the source file of this page.
body
let pub @body: Document
The body of the page.
Static methods
parse_file
Show source codeHide source code
fn pub static parse_file(
source: ref Path,
path: ref Path,
) -> Result[Page, PageError] {
let url = file_url(source, path)
let data = ByteArray.new
try ReadOnlyFile
.new(path.clone)
.then(fn (f) { f.read_all(data) })
.map_error(fn (e) { PageError.Io(path.clone, e) })
let front_md = markdown.split_front_matter(data.into_string)
let front = try FrontMatter.parse(front_md.0).map_error(fn (e) {
PageError.FrontMatter(path.clone, e)
})
let doc = try markdown.Document.parse(front_md.1).map_error(fn (e) {
PageError.Markdown(path.clone, e.to_string)
})
Result.Ok(
Page(front_matter: front, url: url, source_path: path.clone, body: doc),
)
}
fn pub static parse_file(source: ref Path, path: ref Path) -> Result[Page, PageError]
Parses a Page
from a source file path.
The source
argument is the path to the main source directory. The path
argument is the path to the source file (inside the source
directory) that
needs to be parsed.
Instance methods
date
Show source codeHide source code
fn pub date -> ref DateTime {
@front_matter.date
}
fn pub date -> ref DateTime
Returns the date at which the page is created.
title
Show source codeHide source code
fn pub title -> String {
@front_matter.title
}
fn pub title -> String
Returns the title of the page.
to_html
Show source codeHide source code
fn pub to_html(filters: Array[Filter]) -> html.Document {
let doc = @body.to_html
filters.into_iter.each(fn (filter) { filter.run(doc) })
doc
}
fn pub to_html(filters: Array[Filter]) -> Document
Converts the Markdown to an HTML document.
The filters
array is a list of Markdown filters to apply to the HTML
document.