summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2011-06-10 20:09:27 +0200
committerJasper Van der Jeugt <jaspervdj@gmail.com>2011-06-10 20:09:27 +0200
commit0b4abde7cc4be3f4ccfe9598096f9cfdfb481382 (patch)
treef0a130be437b385594a9eb053b59d76cd23815e0 /src
parent1ccc5fd65b599914d5b5946a4e9aec5ef7c7ae80 (diff)
downloadhakyll-0b4abde7cc4be3f4ccfe9598096f9cfdfb481382.tar.gz
Add setPageField
Diffstat (limited to 'src')
-rw-r--r--src/Hakyll/Web/Page/Metadata.hs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/Hakyll/Web/Page/Metadata.hs b/src/Hakyll/Web/Page/Metadata.hs
index 79c616e..89e17b6 100644
--- a/src/Hakyll/Web/Page/Metadata.hs
+++ b/src/Hakyll/Web/Page/Metadata.hs
@@ -6,6 +6,7 @@ module Hakyll.Web.Page.Metadata
, setField
, trySetField
, setFieldA
+ , setFieldPage
, renderField
, changeField
, copyField
@@ -17,7 +18,7 @@ module Hakyll.Web.Page.Metadata
import Prelude hiding (id)
import Control.Category (id)
-import Control.Arrow (Arrow, (>>>), (***), arr)
+import Control.Arrow (Arrow, arr, (>>>), (***), (&&&))
import Data.List (intercalate)
import Data.Maybe (fromMaybe)
import Data.Time.Clock (UTCTime)
@@ -28,6 +29,8 @@ import System.Locale (TimeLocale, defaultTimeLocale)
import Hakyll.Web.Page.Internal
import Hakyll.Core.Util.String
+import Hakyll.Core.Identifier
+import Hakyll.Core.Compiler
-- | Get a metadata field. If the field does not exist, the empty string is
-- returned.
@@ -69,6 +72,13 @@ setFieldA :: Arrow a
-> a (Page b, x) (Page b) -- ^ Resulting arrow
setFieldA k v = id *** v >>> arr (uncurry $ flip $ setField k)
+-- | Set a field of a page to the contents of another page
+--
+setFieldPage :: String -- ^ Key to add the page under
+ -> Identifier (Page String) -- ^ Page to add
+ -> Compiler (Page a) (Page a) -- ^ Page compiler
+setFieldPage key page = id &&& require_ page >>> setFieldA key (arr pageBody)
+
-- | Do something with a metadata value, but keep the old value as well. If the
-- key given is not present in the metadata, nothing will happen. If the source
-- and destination keys are the same, the value will be changed (but you should