-- | Front matter keys the site knows about, and how they are spelled
module MathiasSM.Metadata (
    Key (..),
    keyName,
    lookupKey,
)
where

import Hakyll (Metadata, lookupString)

{- | Every front matter key that content may use.

Add a constructor here (and in 'keyName') before using a new key anywhere.
-}
data Key
    = -- Keys Hakyll itself interprets
      Title
    | Date
    | Published
    | -- Keys specific to this site
      Description
    | Aliases
    | Draft
    | EndDate
    | Group
    | HideDescription
    | Home
    | Href
    | Icon
    | Index
    | Language
    | LastModifiedAt
    | LongDescription
    | Name
    | Nav
    | NavOrder
    | Path
    | Priority
    | Project
    | ShareDescription
    | ShareTitle
    | ShortDescription
    | Show
    | ShowAbout
    | ShowContact
    | Sitemap
    | StartDate
    | Status
    | Team
    | Templated
    | TOC
    | Type
    | Username
    deriving (Key -> Key -> Bool
(Key -> Key -> Bool) -> (Key -> Key -> Bool) -> Eq Key
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Key -> Key -> Bool
== :: Key -> Key -> Bool
$c/= :: Key -> Key -> Bool
/= :: Key -> Key -> Bool
Eq, Int -> Key -> ShowS
[Key] -> ShowS
Key -> String
(Int -> Key -> ShowS)
-> (Key -> String) -> ([Key] -> ShowS) -> Show Key
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Key -> ShowS
showsPrec :: Int -> Key -> ShowS
$cshow :: Key -> String
show :: Key -> String
$cshowList :: [Key] -> ShowS
showList :: [Key] -> ShowS
Show, Int -> Key
Key -> Int
Key -> [Key]
Key -> Key
Key -> Key -> [Key]
Key -> Key -> Key -> [Key]
(Key -> Key)
-> (Key -> Key)
-> (Int -> Key)
-> (Key -> Int)
-> (Key -> [Key])
-> (Key -> Key -> [Key])
-> (Key -> Key -> [Key])
-> (Key -> Key -> Key -> [Key])
-> Enum Key
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Key -> Key
succ :: Key -> Key
$cpred :: Key -> Key
pred :: Key -> Key
$ctoEnum :: Int -> Key
toEnum :: Int -> Key
$cfromEnum :: Key -> Int
fromEnum :: Key -> Int
$cenumFrom :: Key -> [Key]
enumFrom :: Key -> [Key]
$cenumFromThen :: Key -> Key -> [Key]
enumFromThen :: Key -> Key -> [Key]
$cenumFromTo :: Key -> Key -> [Key]
enumFromTo :: Key -> Key -> [Key]
$cenumFromThenTo :: Key -> Key -> Key -> [Key]
enumFromThenTo :: Key -> Key -> Key -> [Key]
Enum, Key
Key -> Key -> Bounded Key
forall a. a -> a -> Bounded a
$cminBound :: Key
minBound :: Key
$cmaxBound :: Key
maxBound :: Key
Bounded)

-- | The key as spelled in front matter
keyName :: Key -> String
keyName :: Key -> String
keyName Key
key = case Key
key of
    Key
Title -> String
"title"
    Key
Date -> String
"date"
    Key
Published -> String
"published"
    Key
Description -> String
"description"
    Key
Aliases -> String
"aliases"
    Key
Draft -> String
"draft"
    Key
EndDate -> String
"endDate"
    Key
Group -> String
"group"
    Key
HideDescription -> String
"hideDescription"
    Key
Home -> String
"home"
    Key
Href -> String
"href"
    Key
Icon -> String
"icon"
    Key
Index -> String
"index"
    Key
Language -> String
"language"
    Key
LastModifiedAt -> String
"lastModifiedAt"
    Key
LongDescription -> String
"longDescription"
    Key
Name -> String
"name"
    Key
Nav -> String
"nav"
    Key
NavOrder -> String
"navOrder"
    Key
Path -> String
"path"
    Key
Priority -> String
"priority"
    Key
Project -> String
"project"
    Key
ShareDescription -> String
"shareDescription"
    Key
ShareTitle -> String
"shareTitle"
    Key
ShortDescription -> String
"shortDescription"
    Key
Show -> String
"show"
    Key
ShowAbout -> String
"showAbout"
    Key
ShowContact -> String
"showContact"
    Key
Sitemap -> String
"sitemap"
    Key
StartDate -> String
"startDate"
    Key
Status -> String
"status"
    Key
Team -> String
"team"
    Key
Templated -> String
"templated"
    Key
TOC -> String
"TOC"
    Key
Type -> String
"type"
    Key
Username -> String
"username"

-- | Looks up a key's value as a string
lookupKey :: Key -> Metadata -> Maybe String
lookupKey :: Key -> Metadata -> Maybe String
lookupKey = String -> Metadata -> Maybe String
lookupString (String -> Metadata -> Maybe String)
-> (Key -> String) -> Key -> Metadata -> Maybe String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key -> String
keyName