@@ -6,13 +6,14 @@ module Text.Hakyll.ContextManipulations
6 , changeUrl
6 , changeUrl
7 , copyValue
7 , copyValue
8 , renderDate
8 , renderDate
9+ , renderDateWithLocale
9 , changeExtension
10 , changeExtension
10 , renderBody
11 , renderBody
13import Control.Monad (liftM)
14import Control.Monad (liftM)
14import Control.Arrow (arr)
15import Control.Arrow (arr)
15−import System.Locale (defaultTimeLocale)
16+import System.Locale (TimeLocale, defaultTimeLocale)
16import System.FilePath (takeFileName, addExtension, dropExtension)
17import System.FilePath (takeFileName, addExtension, dropExtension)
17import Data.Time.Format (parseTime, formatTime)
18import Data.Time.Format (parseTime, formatTime)
18import Data.Time.Clock (UTCTime)
19import Data.Time.Clock (UTCTime)
@@ -66,11 +67,24 @@ copyValue source destination = renderValue source destination id
66-- > renderDate "date" "%B %e, %Y" "Date unknown"
67-- > renderDate "date" "%B %e, %Y" "Date unknown"
68-- Will render something like @January 32, 2010@.
69-- Will render something like @January 32, 2010@.
69renderDate :: String -- ^ Key in which the rendered date should be placed.
71renderDate :: String -- ^ Key in which the rendered date should be placed.
70 -> String -- ^ Format to use on the date.
72 -> String -- ^ Format to use on the date.
71 -> String -- ^ Default key, in case the date cannot be parsed.
73 -> String -- ^ Default key, in case the date cannot be parsed.
72 -> HakyllAction Context Context
74 -> HakyllAction Context Context
75+renderDate = renderDateWithLocale defaultTimeLocale
77+-- | This is an extended version of 'renderDate' that allows you to specify a
78+-- time locale that is used for outputting the date. For more details, see
81+renderDateWithLocale :: TimeLocale -- ^ Output time locale.
82+ -> String -- ^ Destination key.
83+ -> String -- ^ Format to use on the date.
84+ -> String -- ^ Default key.
85+ -> HakyllAction Context Context
86+renderDateWithLocale locale key format defaultValue =
73−renderDate key format defaultValue = renderValue "path" key renderDate'
87+ renderValue "path" key renderDate'
75 renderDate' filePath = fromMaybe defaultValue $ do
89 renderDate' filePath = fromMaybe defaultValue $ do
76 let dateString = substituteRegex "^([0-9]*-[0-9]*-[0-9]*).*" "\\1"
90 let dateString = substituteRegex "^([0-9]*-[0-9]*-[0-9]*).*" "\\1"
@@ -78,7 +92,7 @@ renderDate key format defaultValue = renderValue "path" key renderDate'
78 time <- parseTime defaultTimeLocale
92 time <- parseTime defaultTimeLocale
79 "%Y-%m-%d"
93 "%Y-%m-%d"
80 dateString :: Maybe UTCTime
94 dateString :: Maybe UTCTime
81− return $ formatTime defaultTimeLocale format time
95+ return $ formatTime locale format time
83-- | Change the extension of a file. This is only needed when you want to
97-- | Change the extension of a file. This is only needed when you want to
84-- render, for example, mardown to @.php@ files instead of @.html@ files.
98-- render, for example, mardown to @.php@ files instead of @.html@ files.