summaryrefslogtreecommitdiff
path: root/src/Hakyll/Web/Template
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2012-11-10 18:11:46 +0100
committerJasper Van der Jeugt <m@jaspervdj.be>2012-11-10 18:11:46 +0100
commit141e761ce11d4d4ae9e9b86201249dbd549e2924 (patch)
tree0d0ba398331bceb9326c58392680fb81361fb6c3 /src/Hakyll/Web/Template
parent260e4e2e8936f756d2f3a2e6e788f05ca28e4324 (diff)
downloadhakyll-141e761ce11d4d4ae9e9b86201249dbd549e2924.tar.gz
Deprecate things, basics now work
Diffstat (limited to 'src/Hakyll/Web/Template')
-rw-r--r--src/Hakyll/Web/Template/Context.hs33
1 files changed, 20 insertions, 13 deletions
diff --git a/src/Hakyll/Web/Template/Context.hs b/src/Hakyll/Web/Template/Context.hs
index 17db7ca..4273b79 100644
--- a/src/Hakyll/Web/Template/Context.hs
+++ b/src/Hakyll/Web/Template/Context.hs
@@ -13,60 +13,67 @@ module Hakyll.Web.Template.Context
--------------------------------------------------------------------------------
-import Control.Applicative (empty, (<|>))
+import Control.Applicative (empty, (<|>))
import Control.Arrow
-import System.FilePath (takeBaseName, takeDirectory)
+import System.FilePath (takeBaseName, takeDirectory)
--------------------------------------------------------------------------------
import Hakyll.Core.Compiler
import Hakyll.Core.Identifier
+import Hakyll.Web.Page.Internal
import Hakyll.Web.Urls
--------------------------------------------------------------------------------
-type Context a = Compiler (String, a) String
+type Context a = Compiler (String, (Identifier a, a)) String
--------------------------------------------------------------------------------
-field :: String -> Compiler a String -> Context a
-field key value = arr checkKey >>> empty ||| value
+field :: String -> Compiler (Identifier a, a) String -> Context a
+field key value = arr checkKey >>> (empty ||| value)
where
checkKey (k, x)
- | k == key = Left ()
+ | k /= key = Left ()
| otherwise = Right x
--------------------------------------------------------------------------------
-defaultContext :: Context (Identifier String, String)
+defaultContext :: Context Page
defaultContext =
bodyField "body" <|>
urlField "url" <|>
pathField "path" <|>
categoryField "category" <|>
- titleField "title"
+ titleField "title" <|>
+ missingField
--------------------------------------------------------------------------------
-bodyField :: String -> Context (Identifier String, String)
+bodyField :: String -> Context Page
bodyField key = field key $ arr snd
--------------------------------------------------------------------------------
-urlField :: String -> Context (Identifier a, a)
+urlField :: String -> Context a
urlField key = field key $ fst ^>> getRouteFor >>^ maybe empty toUrl
--------------------------------------------------------------------------------
-pathField :: String -> Context (Identifier a, a)
+pathField :: String -> Context a
pathField key = field key $ arr $ toFilePath . fst
--------------------------------------------------------------------------------
-categoryField :: String -> Context (Identifier a, a)
+categoryField :: String -> Context a
categoryField key = pathField key >>^ (takeBaseName . takeDirectory)
--------------------------------------------------------------------------------
-titleField :: String -> Context (Identifier a, a)
+titleField :: String -> Context a
titleField key = pathField key >>^ takeBaseName
+
+
+--------------------------------------------------------------------------------
+missingField :: Context a
+missingField = arr $ \(k, _) -> "$" ++ k ++ "$"