diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-10-28 01:13:37 +0200 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-10-28 01:13:37 +0200 |
commit | cb1fec60f58fd6225cbae90154af886237e1a5ce (patch) | |
tree | 81865d1ca0f1cb201ca3047d4e2b6e52906b2a9e /src/Text | |
parent | 968789368fe72f4f8a00b2211fe2b43b8faee585 (diff) | |
download | hakyll-cb1fec60f58fd6225cbae90154af886237e1a5ce.tar.gz |
Add an `addField` function
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Hakyll/CreateContext.hs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/Text/Hakyll/CreateContext.hs b/src/Text/Hakyll/CreateContext.hs index a9c3a95..f894ff0 100644 --- a/src/Text/Hakyll/CreateContext.hs +++ b/src/Text/Hakyll/CreateContext.hs @@ -5,12 +5,13 @@ module Text.Hakyll.CreateContext ( createPage , createCustomPage , createListing + , addField , combine , combineWithUrl ) where import qualified Data.Map as M -import Control.Arrow (second) +import Control.Arrow (second, arr, (&&&)) import Control.Monad (liftM2) import Control.Applicative ((<$>)) import Control.Arrow ((>>>)) @@ -27,13 +28,14 @@ import Text.Hakyll.Internal.Cache createPage :: FilePath -> HakyllAction () Context createPage path = cacheAction "pages" $ readPageAction path >>> renderAction --- | Create a "custom page" @Context@. +-- | Create a custom page @Context@. -- -- The association list given maps keys to values for substitution. Note -- that as value, you can either give a @String@ or a -- @HakyllAction () String@. The latter is preferred for more complex data, -- since it allows dependency checking. A @String@ is obviously more simple -- to use in some cases. +-- createCustomPage :: FilePath -> [(String, Either String (HakyllAction () String))] -> HakyllAction () Context @@ -67,6 +69,17 @@ createListing url templates renderables additional = context = ("body", Right concatenation) : additional concatenation = renderAndConcat templates renderables +-- | Add a field to a 'Context'. +-- +addField :: String -- ^ Key + -> Either String (HakyllAction () String) -- ^ Value + -> HakyllAction a Context -- ^ Target + -> HakyllAction a Context -- ^ Result +addField key value target = value' &&& target >>> arr (uncurry insert) + where + value' = arr (const ()) >>> either (arr . const) id value + insert v = Context . M.insert key v . unContext + -- | Combine two @Context@s. The url will always be taken from the first -- @Renderable@. Also, if a `$key` is present in both renderables, the -- value from the first @Context@ will be taken as well. |