diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-12-31 09:04:02 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-12-31 09:04:02 +0100 |
commit | 7b84181dab7c45c48be5db5b68e31ad5880b05cc (patch) | |
tree | 0b48f314426e133ac0aeba6b2e83d75305db1596 | |
parent | 15f2cee5e444735c4206e0e98e8f2506d9fb8659 (diff) | |
download | hakyll-7b84181dab7c45c48be5db5b68e31ad5880b05cc.tar.gz |
Add $category field
-rw-r--r-- | src/Hakyll/Web/Page.hs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/Hakyll/Web/Page.hs b/src/Hakyll/Web/Page.hs index 6e94d52..6fed202 100644 --- a/src/Hakyll/Web/Page.hs +++ b/src/Hakyll/Web/Page.hs @@ -14,9 +14,7 @@ module Hakyll.Web.Page import Prelude hiding (id) import Control.Category (id) import Control.Arrow ((>>^), (&&&), (>>>)) -import Control.Applicative ((<$>)) -import System.FilePath (takeBaseName) -import Data.Maybe (fromMaybe) +import System.FilePath (takeBaseName, takeDirectory) import Data.Map (Map) import qualified Data.Map as M @@ -54,8 +52,15 @@ pageRead = getResourceString >>^ readPage -- addDefaultFields :: Compiler (Page a) (Page a) addDefaultFields = (getRoute &&& id >>^ uncurry addRoute) - >>> (getIdentifier &&& id >>^ uncurry addTitle) + >>> (getIdentifier &&& id >>^ uncurry addIdentifier) where - addRoute r = addField "url" (fromMaybe "?" r) - . addField "root" (fromMaybe "/" $ toSiteRoot <$> r) - addTitle i = addField "title" (takeBaseName $ toFilePath i) + -- Add root and url, based on route + addRoute Nothing = id + addRoute (Just r) = addField "url" r + . addField "root" (toSiteRoot r) + + -- Add title and category, based on identifier + addIdentifier i = addField "title" (takeBaseName p) + . addField "category" (takeBaseName $ takeDirectory p) + where + p = toFilePath i |