summaryrefslogtreecommitdiff
path: root/src/Hakyll/Web/Page
diff options
context:
space:
mode:
Diffstat (limited to 'src/Hakyll/Web/Page')
-rw-r--r--src/Hakyll/Web/Page/Metadata.hs28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/Hakyll/Web/Page/Metadata.hs b/src/Hakyll/Web/Page/Metadata.hs
index efae390..69c4608 100644
--- a/src/Hakyll/Web/Page/Metadata.hs
+++ b/src/Hakyll/Web/Page/Metadata.hs
@@ -118,11 +118,15 @@ copyField :: String -- ^ Key to copy
-> Page a -- ^ Resulting page
copyField src dst = renderField src dst id
--- | When the metadata has a field called @path@ in a
+-- | When the metadata has a field called @datetime@ in a
+-- format such as "January 1, 2000 1:00 AM", then
+-- this function can render the date.
+--
+-- Alternatively, when the metadata has a field called @path@ in a
-- @folder/yyyy-mm-dd-title.extension@ format (the convention for pages),
-- this function can render the date.
--
--- > renderDate "date" "%B %e, %Y" "Date unknown"
+-- > renderDateField "date" "%B %e, %Y" "Date unknown"
--
-- Will render something like @January 32, 2010@.
--
@@ -143,19 +147,25 @@ renderDateFieldWith :: TimeLocale -- ^ Output time locale
-> String -- ^ Default value
-> Page a -- ^ Target page
-> Page a -- ^ Resulting page
-renderDateFieldWith locale key format defaultValue =
- renderField "path" key renderDate'
+renderDateFieldWith locale key format defaultValue page =
+ setField key renderTimeString page
where
- renderDate' filePath = fromMaybe defaultValue $ do
+ renderTimeString = fromMaybe renderDateString $ do
+ dateString <- getFieldMaybe "datetime" page
+ time <- parseTime locale "%B %e, %Y %l:%M %P" dateString :: Maybe UTCTime
+ return $ formatTime locale format time
+ renderDateString = fromMaybe renderFilePathDate $ do
+ dateString <- getFieldMaybe "datetime" page
+ time <- parseTime locale "%B %e, %Y" dateString :: Maybe UTCTime
+ return $ formatTime locale format time
+ renderFilePathDate = fromMaybe defaultValue $ do
+ filePath <- getFieldMaybe "path" page
let dateString = intercalate "-" $ take 3
$ splitAll "-" $ takeFileName filePath
- time <- parseTime defaultTimeLocale
- "%Y-%m-%d"
- dateString :: Maybe UTCTime
+ time <- parseTime locale "%Y-%m-%d" dateString :: Maybe UTCTime
return $ formatTime locale format time
-- | Set the modification time as a field in the page
---
renderModificationTime :: String
-- ^ Destination key
-> String