@@ -12,6 +12,8 @@ module Hakyll.Web.Page.Metadata
1212 , copyField
1313 , renderDateField
1414 , renderDateFieldWith
15+ , renderModificationTime
16+ , renderModificationTimeWith
1517 , copyBodyToField
1618 , copyBodyFromField
1719 ) where
@@ -31,6 +33,7 @@ import Hakyll.Web.Page.Internal
3133import Hakyll.Core.Util.String
3234import Hakyll.Core.Identifier
3335import Hakyll.Core.Compiler
36+import Hakyll.Core.Resource.Provider
3437
3538-- | Get a metadata field. If the field does not exist, the empty string is
3639-- returned.
@@ -151,6 +154,28 @@ renderDateFieldWith locale key format defaultValue =
151154 dateString :: Maybe UTCTime
152155 return $ formatTime locale format time
153156
157+-- | Set the modification time as a field in the page
158+--
159+renderModificationTime :: String
160+ -- ^ Destination key
161+ -> String
162+ -- ^ Format to use on the time
163+ -> Compiler (Page String) (Page String)
164+ -- ^ Resulting compiler
165+renderModificationTime = renderModificationTimeWith defaultTimeLocale
166+
167+renderModificationTimeWith :: TimeLocale
168+ -- ^ Output time locale
169+ -> String
170+ -- ^ Destination key
171+ -> String
172+ -- ^ Format to use on the time
173+ -> Compiler (Page String) (Page String)
174+ -- ^ Resulting compiler
175+renderModificationTimeWith locale key format =
176+ id &&& (getResource >>> getResourceWith resourceModificationTime) >>>
177+ setFieldA key (arr (formatTime locale format))
178+
154179-- | Copy the body of a page to a metadata field
155180--
156181copyBodyToField :: String -- ^ Destination key