The Document represents all the ways to handle the frontmatter metadata
and documents found in your content folder.
Frontmatter content is turned into JSON, so you can use the familiar Elm JSON decoding to get frontmatter content. And you'll get helpful error messages if any of your frontmatter is invalid (which will prevent an invalid production build from being created!).
It's up to you how you parse your metadata and content. Here's a simple example of
a site that has two types of pages, blog posts and page (a regular page like /about or /).
content/index.md
---
type: page
title: Welcome to my site!
---
# Here's my site!
I built it with `elm-pages`! 🚀content/blog/hello-world.md
---
type: blog
author: Dillon Kearns
title: Hello, World!
---
# Hello, World! 👋
## This will be parsed as markdown
Hello!!!-- this example uses elm-explorations/markdown
import Html exposing (Html)
import Json.Decode as Decode exposing (Decoder)
import Markdown
import Pages.Document
type Metadata
= Blog { title : String, description : String, author : String }
| Page { title : String }
markdownDocument : ( String, Pages.Document.DocumentHandler Metadata (Html msg) )
markdownDocument =
Pages.Document.parser
{ extension = "md"
, metadata = frontmatterDecoder
, body = Markdown.toHtml []
}
frontmatterDecoder : Decoder Metadata
frontmatterDecoder =
Decode.field "type" Decode.string
|> Decode.andThen
(\metadataType ->
case metadataType of
"blog" ->
Decode.map3 (\title description author -> { title = title, description = description, author = author })
(Decode.field "title" Decode.string)
(Decode.field "description" Decode.string)
(Decode.field "author" Decode.string)
"page" ->
Decode.map (\title -> { title = title })
(Decode.field "title" Decode.string)
)How to parse the frontmatter and content for a given extension. Build one
using Document.parser (see above for an example).
Create a Document Handler for the given extension.
Register an elm-markup
parser for your .emu files.
Used by the generated Pages.elm module. There's no need to use this
outside of the generated code.
Represents all of the
DocumentHandlers. You register a handler for each extension that tells it how to parse frontmatter and content for that extension.