{-# LANGUAGE CPP #-}
{-# LANGUAGE ExistentialQuantification #-}
module Hakyll.Web.Template.Context
( ContextField (..)
, Context (..)
, field
, boolField
, boolFieldM
, constField
, listField
, listFieldWith
, functionField
, mapContext
, mapContextBy
, defaultContext
, bodyField
, metadataField
, urlField
, pathField
, titleField
, snippetField
, dateField
, dateFieldWith
, getItemUTC
, getItemModificationTime
, modificationTimeField
, modificationTimeFieldWith
, teaserField
, teaserFieldWithSeparator
, missingField
) where
import Control.Applicative (Alternative (..))
import Control.Monad (msum)
#if !MIN_VERSION_base(4,13,0)
import Control.Monad.Fail (MonadFail)
#endif
import Data.List (intercalate, tails)
import Data.Time.Clock (UTCTime (..))
import Data.Time.Format (formatTime, parseTimeM)
import Data.Time.Locale.Compat (TimeLocale, defaultTimeLocale)
import Hakyll.Core.Compiler
import Hakyll.Core.Compiler.Internal
import Hakyll.Core.Identifier
import Hakyll.Core.Item
import Hakyll.Core.Metadata
import Hakyll.Core.Provider
import Hakyll.Core.Util.String (needlePrefix, splitAll)
import Hakyll.Web.Html
import Prelude hiding (id)
import System.FilePath (dropExtension, splitDirectories,
takeBaseName)
data ContextField
= EmptyField
| StringField String
| forall a. ListField (Context a) [Item a]
newtype Context a = Context
{ forall a.
Context a -> String -> [String] -> Item a -> Compiler ContextField
unContext :: String -> [String] -> Item a -> Compiler ContextField
}
instance Semigroup (Context a) where
<> :: Context a -> Context a -> Context a
(<>) (Context String -> [String] -> Item a -> Compiler ContextField
f) (Context String -> [String] -> Item a -> Compiler ContextField
g) = (String -> [String] -> Item a -> Compiler ContextField)
-> Context a
forall a.
(String -> [String] -> Item a -> Compiler ContextField)
-> Context a
Context ((String -> [String] -> Item a -> Compiler ContextField)
-> Context a)
-> (String -> [String] -> Item a -> Compiler ContextField)
-> Context a
forall a b. (a -> b) -> a -> b
$ \String
k [String]
a Item a
i -> String -> [String] -> Item a -> Compiler ContextField
f String
k [String]
a Item a
i Compiler ContextField
-> Compiler ContextField -> Compiler ContextField
forall a. Compiler a -> Compiler a -> Compiler a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> String -> [String] -> Item a -> Compiler ContextField
g String
k [String]
a Item a
i
instance Monoid (Context a) where
mempty :: Context a
mempty = Context a
forall a. Context a
missingField
mappend :: Context a -> Context a -> Context a
mappend = Context a -> Context a -> Context a
forall a. Semigroup a => a -> a -> a
(<>)
field' :: String -> (Item a -> Compiler ContextField) -> Context a
field' :: forall a. String -> (Item a -> Compiler ContextField) -> Context a
field' String
key Item a -> Compiler ContextField
value = (String -> [String] -> Item a -> Compiler ContextField)
-> Context a
forall a.
(String -> [String] -> Item a -> Compiler ContextField)
-> Context a
Context ((String -> [String] -> Item a -> Compiler ContextField)
-> Context a)
-> (String -> [String] -> Item a -> Compiler ContextField)
-> Context a
forall a b. (a -> b) -> a -> b
$ \String
k [String]
_ Item a
i ->
if String
k String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
key
then Item a -> Compiler ContextField
value Item a
i
else String -> Compiler ContextField
forall a. String -> Compiler a
noResult (String -> Compiler ContextField)
-> String -> Compiler ContextField
forall a b. (a -> b) -> a -> b
$ String
"Tried field " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
key
field
:: String
-> (Item a -> Compiler String)
-> Context a
field :: forall a. String -> (Item a -> Compiler String) -> Context a
field String
key Item a -> Compiler String
value = String -> (Item a -> Compiler ContextField) -> Context a
forall a. String -> (Item a -> Compiler ContextField) -> Context a
field' String
key ((String -> ContextField)
-> Compiler String -> Compiler ContextField
forall a b. (a -> b) -> Compiler a -> Compiler b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> ContextField
StringField (Compiler String -> Compiler ContextField)
-> (Item a -> Compiler String) -> Item a -> Compiler ContextField
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Item a -> Compiler String
value)
boolField
:: String
-> (Item a -> Bool)
-> Context a
boolField :: forall a. String -> (Item a -> Bool) -> Context a
boolField String
name Item a -> Bool
f = String -> (Item a -> Compiler Bool) -> Context a
forall a. String -> (Item a -> Compiler Bool) -> Context a
boolFieldM String
name (Bool -> Compiler Bool
forall a. a -> Compiler a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> Compiler Bool)
-> (Item a -> Bool) -> Item a -> Compiler Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Item a -> Bool
f)
boolFieldM
:: String
-> (Item a -> Compiler Bool)
-> Context a
boolFieldM :: forall a. String -> (Item a -> Compiler Bool) -> Context a
boolFieldM String
name Item a -> Compiler Bool
f = String -> (Item a -> Compiler ContextField) -> Context a
forall a. String -> (Item a -> Compiler ContextField) -> Context a
field' String
name (\Item a
i -> do
b <- Item a -> Compiler Bool
f Item a
i
if b
then return EmptyField
else noResult $ "Field " ++ name ++ " is false")
constField :: String
-> String
-> Context a
constField :: forall a. String -> String -> Context a
constField String
key = String -> (Item a -> Compiler String) -> Context a
forall a. String -> (Item a -> Compiler String) -> Context a
field String
key ((Item a -> Compiler String) -> Context a)
-> (String -> Item a -> Compiler String) -> String -> Context a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Compiler String -> Item a -> Compiler String
forall a b. a -> b -> a
const (Compiler String -> Item a -> Compiler String)
-> (String -> Compiler String)
-> String
-> Item a
-> Compiler String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Compiler String
forall a. a -> Compiler a
forall (m :: * -> *) a. Monad m => a -> m a
return
listField :: String -> Context a -> Compiler [Item a] -> Context b
listField :: forall a b. String -> Context a -> Compiler [Item a] -> Context b
listField String
key Context a
c Compiler [Item a]
xs = String -> Context a -> (Item b -> Compiler [Item a]) -> Context b
forall a b.
String -> Context a -> (Item b -> Compiler [Item a]) -> Context b
listFieldWith String
key Context a
c (Compiler [Item a] -> Item b -> Compiler [Item a]
forall a b. a -> b -> a
const Compiler [Item a]
xs)
listFieldWith
:: String -> Context a -> (Item b -> Compiler [Item a]) -> Context b
listFieldWith :: forall a b.
String -> Context a -> (Item b -> Compiler [Item a]) -> Context b
listFieldWith String
key Context a
c Item b -> Compiler [Item a]
f = String -> (Item b -> Compiler ContextField) -> Context b
forall a. String -> (Item a -> Compiler ContextField) -> Context a
field' String
key ((Item b -> Compiler ContextField) -> Context b)
-> (Item b -> Compiler ContextField) -> Context b
forall a b. (a -> b) -> a -> b
$ ([Item a] -> ContextField)
-> Compiler [Item a] -> Compiler ContextField
forall a b. (a -> b) -> Compiler a -> Compiler b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Context a -> [Item a] -> ContextField
forall a. Context a -> [Item a] -> ContextField
ListField Context a
c) (Compiler [Item a] -> Compiler ContextField)
-> (Item b -> Compiler [Item a]) -> Item b -> Compiler ContextField
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Item b -> Compiler [Item a]
f
functionField :: String
-> ([String] -> Item a -> Compiler String)
-> Context a
functionField :: forall a.
String -> ([String] -> Item a -> Compiler String) -> Context a
functionField String
name [String] -> Item a -> Compiler String
value = (String -> [String] -> Item a -> Compiler ContextField)
-> Context a
forall a.
(String -> [String] -> Item a -> Compiler ContextField)
-> Context a
Context ((String -> [String] -> Item a -> Compiler ContextField)
-> Context a)
-> (String -> [String] -> Item a -> Compiler ContextField)
-> Context a
forall a b. (a -> b) -> a -> b
$ \String
k [String]
args Item a
i ->
if String
k String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
name
then String -> ContextField
StringField (String -> ContextField)
-> Compiler String -> Compiler ContextField
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [String] -> Item a -> Compiler String
value [String]
args Item a
i
else String -> Compiler ContextField
forall a. String -> Compiler a
noResult (String -> Compiler ContextField)
-> String -> Compiler ContextField
forall a b. (a -> b) -> a -> b
$ String
"Tried function field " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
name
mapContext :: (String -> String) -> Context a -> Context a
mapContext :: forall a. (String -> String) -> Context a -> Context a
mapContext = (String -> Bool) -> (String -> String) -> Context a -> Context a
forall a.
(String -> Bool) -> (String -> String) -> Context a -> Context a
mapContextBy (Bool -> String -> Bool
forall a b. a -> b -> a
const Bool
True)
mapContextBy :: (String -> Bool) -> (String -> String) -> Context a -> Context a
mapContextBy :: forall a.
(String -> Bool) -> (String -> String) -> Context a -> Context a
mapContextBy String -> Bool
p String -> String
f (Context String -> [String] -> Item a -> Compiler ContextField
c) = (String -> [String] -> Item a -> Compiler ContextField)
-> Context a
forall a.
(String -> [String] -> Item a -> Compiler ContextField)
-> Context a
Context ((String -> [String] -> Item a -> Compiler ContextField)
-> Context a)
-> (String -> [String] -> Item a -> Compiler ContextField)
-> Context a
forall a b. (a -> b) -> a -> b
$ \String
k [String]
a Item a
i -> do
fld <- String -> [String] -> Item a -> Compiler ContextField
c String
k [String]
a Item a
i
case fld of
ContextField
EmptyField -> String -> Compiler ContextField
forall {m :: * -> *} {a}. MonadFail m => String -> m a
wrongType String
"boolField"
StringField String
str -> ContextField -> Compiler ContextField
forall a. a -> Compiler a
forall (m :: * -> *) a. Monad m => a -> m a
return (ContextField -> Compiler ContextField)
-> ContextField -> Compiler ContextField
forall a b. (a -> b) -> a -> b
$ String -> ContextField
StringField (String -> ContextField) -> String -> ContextField
forall a b. (a -> b) -> a -> b
$
if String -> Bool
p String
k then String -> String
f String
str else String
str
ContextField
_ -> String -> Compiler ContextField
forall {m :: * -> *} {a}. MonadFail m => String -> m a
wrongType String
"ListField"
where
wrongType :: String -> m a
wrongType String
typ = String -> m a
forall a. String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> m a) -> String -> m a
forall a b. (a -> b) -> a -> b
$ String
"Hakyll.Web.Template.Context.mapContext: " String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"can't map over a " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
typ String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"!"
snippetField :: Context String
snippetField :: Context String
snippetField = String
-> ([String] -> Item String -> Compiler String) -> Context String
forall a.
String -> ([String] -> Item a -> Compiler String) -> Context a
functionField String
"snippet" [String] -> Item String -> Compiler String
forall {a} {p}.
(Binary a, Typeable a) =>
[String] -> p -> Compiler a
f
where
f :: [String] -> p -> Compiler a
f [String
contentsPath] p
_ = Identifier -> Compiler a
forall a. (Binary a, Typeable a) => Identifier -> Compiler a
loadBody (String -> Identifier
fromFilePath String
contentsPath)
f [] p
_ = String -> Compiler a
forall a. String -> Compiler a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"No argument to function 'snippet()'"
f [String]
_ p
_ = String -> Compiler a
forall a. String -> Compiler a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Too many arguments to function 'snippet()'"
defaultContext :: Context String
defaultContext :: Context String
defaultContext =
String -> Context String
bodyField String
"body" Context String -> Context String -> Context String
forall a. Monoid a => a -> a -> a
`mappend`
Context String
forall a. Context a
metadataField Context String -> Context String -> Context String
forall a. Monoid a => a -> a -> a
`mappend`
String -> Context String
forall a. String -> Context a
urlField String
"url" Context String -> Context String -> Context String
forall a. Monoid a => a -> a -> a
`mappend`
String -> Context String
forall a. String -> Context a
pathField String
"path" Context String -> Context String -> Context String
forall a. Monoid a => a -> a -> a
`mappend`
String -> Context String
forall a. String -> Context a
titleField String
"title"
teaserSeparator :: String
teaserSeparator :: String
teaserSeparator = String
"<!--more-->"
bodyField :: String -> Context String
bodyField :: String -> Context String
bodyField String
key = String -> (Item String -> Compiler String) -> Context String
forall a. String -> (Item a -> Compiler String) -> Context a
field String
key ((Item String -> Compiler String) -> Context String)
-> (Item String -> Compiler String) -> Context String
forall a b. (a -> b) -> a -> b
$ String -> Compiler String
forall a. a -> Compiler a
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Compiler String)
-> (Item String -> String) -> Item String -> Compiler String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Item String -> String
forall a. Item a -> a
itemBody
metadataField :: Context a
metadataField :: forall a. Context a
metadataField = (String -> [String] -> Item a -> Compiler ContextField)
-> Context a
forall a.
(String -> [String] -> Item a -> Compiler ContextField)
-> Context a
Context ((String -> [String] -> Item a -> Compiler ContextField)
-> Context a)
-> (String -> [String] -> Item a -> Compiler ContextField)
-> Context a
forall a b. (a -> b) -> a -> b
$ \String
k [String]
_ Item a
i -> do
let id :: Identifier
id = Item a -> Identifier
forall a. Item a -> Identifier
itemIdentifier Item a
i
empty' :: Compiler a
empty' = String -> Compiler a
forall a. String -> Compiler a
noResult (String -> Compiler a) -> String -> Compiler a
forall a b. (a -> b) -> a -> b
$ String
"No '" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
k String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"' field in metadata " String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"of item " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Identifier -> String
forall a. Show a => a -> String
show Identifier
id
value <- Identifier -> String -> Compiler (Maybe String)
forall (m :: * -> *).
MonadMetadata m =>
Identifier -> String -> m (Maybe String)
getMetadataField Identifier
id String
k
maybe empty' (return . StringField) value
urlField :: String -> Context a
urlField :: forall a. String -> Context a
urlField String
key = String -> (Item a -> Compiler String) -> Context a
forall a. String -> (Item a -> Compiler String) -> Context a
field String
key ((Item a -> Compiler String) -> Context a)
-> (Item a -> Compiler String) -> Context a
forall a b. (a -> b) -> a -> b
$ \Item a
i -> do
let id :: Identifier
id = Item a -> Identifier
forall a. Item a -> Identifier
itemIdentifier Item a
i
empty' :: [a]
empty' = String -> [a]
forall a. String -> [a]
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> [a]) -> String -> [a]
forall a b. (a -> b) -> a -> b
$ String
"No route url found for item " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Identifier -> String
forall a. Show a => a -> String
show Identifier
id
(Maybe String -> String)
-> Compiler (Maybe String) -> Compiler String
forall a b. (a -> b) -> Compiler a -> Compiler b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (String -> (String -> String) -> Maybe String -> String
forall b a. b -> (a -> b) -> Maybe a -> b
maybe String
forall {a}. [a]
empty' String -> String
toUrl) (Compiler (Maybe String) -> Compiler String)
-> Compiler (Maybe String) -> Compiler String
forall a b. (a -> b) -> a -> b
$ Identifier -> Compiler (Maybe String)
getRoute Identifier
id
pathField :: String -> Context a
pathField :: forall a. String -> Context a
pathField String
key = String -> (Item a -> Compiler String) -> Context a
forall a. String -> (Item a -> Compiler String) -> Context a
field String
key ((Item a -> Compiler String) -> Context a)
-> (Item a -> Compiler String) -> Context a
forall a b. (a -> b) -> a -> b
$ String -> Compiler String
forall a. a -> Compiler a
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Compiler String)
-> (Item a -> String) -> Item a -> Compiler String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Identifier -> String
toFilePath (Identifier -> String)
-> (Item a -> Identifier) -> Item a -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Item a -> Identifier
forall a. Item a -> Identifier
itemIdentifier
titleField :: String -> Context a
titleField :: forall a. String -> Context a
titleField = (String -> String) -> Context a -> Context a
forall a. (String -> String) -> Context a -> Context a
mapContext String -> String
takeBaseName (Context a -> Context a)
-> (String -> Context a) -> String -> Context a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Context a
forall a. String -> Context a
pathField
dateField :: String
-> String
-> Context a
dateField :: forall a. String -> String -> Context a
dateField = TimeLocale -> String -> String -> Context a
forall a. TimeLocale -> String -> String -> Context a
dateFieldWith TimeLocale
defaultTimeLocale
dateFieldWith :: TimeLocale
-> String
-> String
-> Context a
dateFieldWith :: forall a. TimeLocale -> String -> String -> Context a
dateFieldWith TimeLocale
locale String
key String
format = String -> (Item a -> Compiler String) -> Context a
forall a. String -> (Item a -> Compiler String) -> Context a
field String
key ((Item a -> Compiler String) -> Context a)
-> (Item a -> Compiler String) -> Context a
forall a b. (a -> b) -> a -> b
$ \Item a
i -> do
time <- TimeLocale -> Identifier -> Compiler UTCTime
forall (m :: * -> *).
(MonadMetadata m, MonadFail m) =>
TimeLocale -> Identifier -> m UTCTime
getItemUTC TimeLocale
locale (Identifier -> Compiler UTCTime) -> Identifier -> Compiler UTCTime
forall a b. (a -> b) -> a -> b
$ Item a -> Identifier
forall a. Item a -> Identifier
itemIdentifier Item a
i
return $ formatTime locale format time
getItemUTC :: (MonadMetadata m, MonadFail m)
=> TimeLocale
-> Identifier
-> m UTCTime
getItemUTC :: forall (m :: * -> *).
(MonadMetadata m, MonadFail m) =>
TimeLocale -> Identifier -> m UTCTime
getItemUTC TimeLocale
locale Identifier
id' = do
metadata <- Identifier -> m Metadata
forall (m :: * -> *). MonadMetadata m => Identifier -> m Metadata
getMetadata Identifier
id'
let tryField String
k String
fmt = String -> Metadata -> Maybe String
lookupString String
k Metadata
metadata Maybe String -> (String -> Maybe UTCTime) -> Maybe UTCTime
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> String -> Maybe UTCTime
parseTime' String
fmt
paths = String -> [String]
splitDirectories (String -> [String]) -> String -> [String]
forall a b. (a -> b) -> a -> b
$ (String -> String
dropExtension (String -> String)
-> (Identifier -> String) -> Identifier -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Identifier -> String
toFilePath) Identifier
id'
maybe empty' return $ msum $
[tryField "published" fmt | fmt <- formats] ++
[tryField "date" fmt | fmt <- formats] ++
[parseTime' "%Y-%m-%d" $ intercalate "-" $ take 3 $ splitAll "-" fnCand | fnCand <- reverse paths] ++
[parseTime' "%Y-%m-%d" $ intercalate "-" $ fnCand | fnCand <- map (take 3) $ reverse . tails $ paths]
where
empty' :: m a
empty' = String -> m a
forall a. String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> m a) -> String -> m a
forall a b. (a -> b) -> a -> b
$ String
"Hakyll.Web.Template.Context.getItemUTC: " String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"could not parse time for " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Identifier -> String
forall a. Show a => a -> String
show Identifier
id'
parseTime' :: String -> String -> Maybe UTCTime
parseTime' = Bool -> TimeLocale -> String -> String -> Maybe UTCTime
forall (m :: * -> *) t.
(MonadFail m, ParseTime t) =>
Bool -> TimeLocale -> String -> String -> m t
parseTimeM Bool
True TimeLocale
locale
formats :: [String]
formats =
[ String
"%a, %d %b %Y %H:%M:%S %Z"
, String
"%a, %d %b %Y %H:%M:%S"
, String
"%Y-%m-%dT%H:%M:%S%Z"
, String
"%Y-%m-%dT%H:%M:%S"
, String
"%Y-%m-%d %H:%M:%S%Z"
, String
"%Y-%m-%d %H:%M:%S"
, String
"%Y-%m-%d"
, String
"%d.%m.%Y"
, String
"%B %e, %Y %l:%M %p"
, String
"%B %e, %Y"
, String
"%b %d, %Y"
]
getItemModificationTime
:: Identifier
-> Compiler UTCTime
getItemModificationTime :: Identifier -> Compiler UTCTime
getItemModificationTime Identifier
identifier = do
provider <- CompilerRead -> Provider
compilerProvider (CompilerRead -> Provider)
-> Compiler CompilerRead -> Compiler Provider
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Compiler CompilerRead
compilerAsk
return $ resourceModificationTime provider identifier
modificationTimeField :: String
-> String
-> Context a
modificationTimeField :: forall a. String -> String -> Context a
modificationTimeField = TimeLocale -> String -> String -> Context a
forall a. TimeLocale -> String -> String -> Context a
modificationTimeFieldWith TimeLocale
defaultTimeLocale
modificationTimeFieldWith :: TimeLocale
-> String
-> String
-> Context a
modificationTimeFieldWith :: forall a. TimeLocale -> String -> String -> Context a
modificationTimeFieldWith TimeLocale
locale String
key String
fmt = String -> (Item a -> Compiler String) -> Context a
forall a. String -> (Item a -> Compiler String) -> Context a
field String
key ((Item a -> Compiler String) -> Context a)
-> (Item a -> Compiler String) -> Context a
forall a b. (a -> b) -> a -> b
$ \Item a
i -> do
mtime <- Identifier -> Compiler UTCTime
getItemModificationTime (Identifier -> Compiler UTCTime) -> Identifier -> Compiler UTCTime
forall a b. (a -> b) -> a -> b
$ Item a -> Identifier
forall a. Item a -> Identifier
itemIdentifier Item a
i
return $ formatTime locale fmt mtime
teaserField :: String
-> Snapshot
-> Context String
teaserField :: String -> String -> Context String
teaserField = String -> String -> String -> Context String
teaserFieldWithSeparator String
teaserSeparator
teaserFieldWithSeparator :: String
-> String
-> Snapshot
-> Context String
teaserFieldWithSeparator :: String -> String -> String -> Context String
teaserFieldWithSeparator String
separator String
key String
snapshot = String -> (Item String -> Compiler String) -> Context String
forall a. String -> (Item a -> Compiler String) -> Context a
field String
key ((Item String -> Compiler String) -> Context String)
-> (Item String -> Compiler String) -> Context String
forall a b. (a -> b) -> a -> b
$ \Item String
item -> do
body <- Item String -> String
forall a. Item a -> a
itemBody (Item String -> String)
-> Compiler (Item String) -> Compiler String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Identifier -> String -> Compiler (Item String)
forall a.
(Binary a, Typeable a) =>
Identifier -> String -> Compiler (Item a)
loadSnapshot (Item String -> Identifier
forall a. Item a -> Identifier
itemIdentifier Item String
item) String
snapshot
case needlePrefix separator body of
Maybe String
Nothing -> String -> Compiler String
forall a. String -> Compiler a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Compiler String) -> String -> Compiler String
forall a b. (a -> b) -> a -> b
$
String
"Hakyll.Web.Template.Context: no teaser defined for " String -> String -> String
forall a. [a] -> [a] -> [a]
++
Identifier -> String
forall a. Show a => a -> String
show (Item String -> Identifier
forall a. Item a -> Identifier
itemIdentifier Item String
item)
Just String
t -> String -> Compiler String
forall a. a -> Compiler a
forall (m :: * -> *) a. Monad m => a -> m a
return String
t
missingField :: Context a
missingField :: forall a. Context a
missingField = (String -> [String] -> Item a -> Compiler ContextField)
-> Context a
forall a.
(String -> [String] -> Item a -> Compiler ContextField)
-> Context a
Context ((String -> [String] -> Item a -> Compiler ContextField)
-> Context a)
-> (String -> [String] -> Item a -> Compiler ContextField)
-> Context a
forall a b. (a -> b) -> a -> b
$ \String
k [String]
_ Item a
_ -> String -> Compiler ContextField
forall a. String -> Compiler a
noResult (String -> Compiler ContextField)
-> String -> Compiler ContextField
forall a b. (a -> b) -> a -> b
$
String
"Missing field '" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
k String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"' in context"