summaryrefslogtreecommitdiff
path: root/src/Hakyll/Web/Template
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2012-11-10 16:30:38 +0100
committerJasper Van der Jeugt <m@jaspervdj.be>2012-11-10 16:30:38 +0100
commit260e4e2e8936f756d2f3a2e6e788f05ca28e4324 (patch)
tree03c4c7e07f53ac5800fc5255f84465a17d0e5bb7 /src/Hakyll/Web/Template
parent6078e699bbfa8ef131a03c900174edfdd21db000 (diff)
downloadhakyll-260e4e2e8936f756d2f3a2e6e788f05ca28e4324.tar.gz
Context?
Diffstat (limited to 'src/Hakyll/Web/Template')
-rw-r--r--src/Hakyll/Web/Template/Context.hs50
1 files changed, 49 insertions, 1 deletions
diff --git a/src/Hakyll/Web/Template/Context.hs b/src/Hakyll/Web/Template/Context.hs
index 5ca1556..17db7ca 100644
--- a/src/Hakyll/Web/Template/Context.hs
+++ b/src/Hakyll/Web/Template/Context.hs
@@ -2,13 +2,26 @@
module Hakyll.Web.Template.Context
( Context
, field
+
+ , defaultContext
+ , bodyField
+ , urlField
+ , pathField
+ , categoryField
+ , titleField
) where
--------------------------------------------------------------------------------
-import Control.Applicative (empty)
+import Control.Applicative (empty, (<|>))
import Control.Arrow
+import System.FilePath (takeBaseName, takeDirectory)
+
+
+--------------------------------------------------------------------------------
import Hakyll.Core.Compiler
+import Hakyll.Core.Identifier
+import Hakyll.Web.Urls
--------------------------------------------------------------------------------
@@ -22,3 +35,38 @@ field key value = arr checkKey >>> empty ||| value
checkKey (k, x)
| k == key = Left ()
| otherwise = Right x
+
+
+--------------------------------------------------------------------------------
+defaultContext :: Context (Identifier String, String)
+defaultContext =
+ bodyField "body" <|>
+ urlField "url" <|>
+ pathField "path" <|>
+ categoryField "category" <|>
+ titleField "title"
+
+
+--------------------------------------------------------------------------------
+bodyField :: String -> Context (Identifier String, String)
+bodyField key = field key $ arr snd
+
+
+--------------------------------------------------------------------------------
+urlField :: String -> Context (Identifier a, a)
+urlField key = field key $ fst ^>> getRouteFor >>^ maybe empty toUrl
+
+
+--------------------------------------------------------------------------------
+pathField :: String -> Context (Identifier a, a)
+pathField key = field key $ arr $ toFilePath . fst
+
+
+--------------------------------------------------------------------------------
+categoryField :: String -> Context (Identifier a, a)
+categoryField key = pathField key >>^ (takeBaseName . takeDirectory)
+
+
+--------------------------------------------------------------------------------
+titleField :: String -> Context (Identifier a, a)
+titleField key = pathField key >>^ takeBaseName