@@ -12,6 +12,8 @@ module Hakyll.Web.Page.Metadata
12 , copyField
12 , copyField
13 , renderDateField
13 , renderDateField
14 , renderDateFieldWith
14 , renderDateFieldWith
15+ , renderModificationTime
16+ , renderModificationTimeWith
15 , copyBodyToField
17 , copyBodyToField
16 , copyBodyFromField
18 , copyBodyFromField
@@ -31,6 +33,7 @@ import Hakyll.Web.Page.Internal
31import Hakyll.Core.Util.String
33import Hakyll.Core.Util.String
32import Hakyll.Core.Identifier
34import Hakyll.Core.Identifier
33import Hakyll.Core.Compiler
35import Hakyll.Core.Compiler
36+import Hakyll.Core.Resource.Provider
35-- | Get a metadata field. If the field does not exist, the empty string is
38-- | Get a metadata field. If the field does not exist, the empty string is
36-- returned.
39-- returned.
@@ -151,6 +154,28 @@ renderDateFieldWith locale key format defaultValue =
151 dateString :: Maybe UTCTime
154 dateString :: Maybe UTCTime
152 return $ formatTime locale format time
155 return $ formatTime locale format time
157+-- | Set the modification time as a field in the page
159+renderModificationTime :: String
160+ -- ^ Destination key
162+ -- ^ Format to use on the time
163+ -> Compiler (Page String) (Page String)
164+ -- ^ Resulting compiler
165+renderModificationTime = renderModificationTimeWith defaultTimeLocale
167+renderModificationTimeWith :: TimeLocale
168+ -- ^ Output time locale
170+ -- ^ Destination key
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))
154-- | Copy the body of a page to a metadata field
179-- | Copy the body of a page to a metadata field
156copyBodyToField :: String -- ^ Destination key
181copyBodyToField :: String -- ^ Destination key