summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2011-09-19 23:08:40 +0200
committerJasper Van der Jeugt <m@jaspervdj.be>2011-09-19 23:08:40 +0200
commite910d53c44ea7cd3cfd2849a19489412189a9c88 (patch)
tree438a07393eee8f859cef5b31d098033ac655fe02 /src
parent6808c5350e4eafacf115eb24078c61cf59caa4b2 (diff)
downloadhakyll-e910d53c44ea7cd3cfd2849a19489412189a9c88.tar.gz
Add a renderModificationTime function
Diffstat (limited to 'src')
-rw-r--r--src/Hakyll/Core/Compiler.hs1
-rw-r--r--src/Hakyll/Web/Page/Metadata.hs25
2 files changed, 26 insertions, 0 deletions
diff --git a/src/Hakyll/Core/Compiler.hs b/src/Hakyll/Core/Compiler.hs
index d63c420..409cff0 100644
--- a/src/Hakyll/Core/Compiler.hs
+++ b/src/Hakyll/Core/Compiler.hs
@@ -98,6 +98,7 @@ module Hakyll.Core.Compiler
, getRouteFor
, getResourceString
, getResourceLBS
+ , getResourceWith
, fromDependency
, require_
, require
diff --git a/src/Hakyll/Web/Page/Metadata.hs b/src/Hakyll/Web/Page/Metadata.hs
index 89e17b6..efae390 100644
--- a/src/Hakyll/Web/Page/Metadata.hs
+++ b/src/Hakyll/Web/Page/Metadata.hs
@@ -12,6 +12,8 @@ module Hakyll.Web.Page.Metadata
, copyField
, renderDateField
, renderDateFieldWith
+ , renderModificationTime
+ , renderModificationTimeWith
, copyBodyToField
, copyBodyFromField
) where
@@ -31,6 +33,7 @@ import Hakyll.Web.Page.Internal
import Hakyll.Core.Util.String
import Hakyll.Core.Identifier
import Hakyll.Core.Compiler
+import Hakyll.Core.Resource.Provider
-- | Get a metadata field. If the field does not exist, the empty string is
-- returned.
@@ -151,6 +154,28 @@ renderDateFieldWith locale key format defaultValue =
dateString :: Maybe UTCTime
return $ formatTime locale format time
+-- | Set the modification time as a field in the page
+--
+renderModificationTime :: String
+ -- ^ Destination key
+ -> String
+ -- ^ Format to use on the time
+ -> Compiler (Page String) (Page String)
+ -- ^ Resulting compiler
+renderModificationTime = renderModificationTimeWith defaultTimeLocale
+
+renderModificationTimeWith :: TimeLocale
+ -- ^ Output time locale
+ -> String
+ -- ^ Destination key
+ -> String
+ -- ^ Format to use on the time
+ -> Compiler (Page String) (Page String)
+ -- ^ Resulting compiler
+renderModificationTimeWith locale key format =
+ id &&& (getResource >>> getResourceWith resourceModificationTime) >>>
+ setFieldA key (arr (formatTime locale format))
+
-- | Copy the body of a page to a metadata field
--
copyBodyToField :: String -- ^ Destination key