on master help sign in
User can supply custom time locale for renderDate
commit6059de5401c49d1dbf49d9283b0773ed9cbcb843 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateTue 22 Jun 2010, 11:53 (16 years ago) parent739be36
1 file changed+17−3
src/Text/Hakyll/ContextManipulations.hs+17−3
src/Text/Hakyll/ContextManipulations.hs+17−3
@@ -6,13 +6,14 @@ module Text.Hakyll.ContextManipulations
66 , changeUrl
77 , copyValue
88 , renderDate
9+ , renderDateWithLocale
910 , changeExtension
1011 , renderBody
1112 ) where
1213
1314import Control.Monad (liftM)
1415import Control.Arrow (arr)
15−import System.Locale (defaultTimeLocale)
16+import System.Locale (TimeLocale, defaultTimeLocale)
1617import System.FilePath (takeFileName, addExtension, dropExtension)
1718import Data.Time.Format (parseTime, formatTime)
1819import Data.Time.Clock (UTCTime)
@@ -66,11 +67,24 @@ copyValue source destination = renderValue source destination id
6667-- > renderDate "date" "%B %e, %Y" "Date unknown"
6768--
6869-- Will render something like @January 32, 2010@.
70+--
6971renderDate :: String -- ^ Key in which the rendered date should be placed.
7072 -> String -- ^ Format to use on the date.
7173 -> String -- ^ Default key, in case the date cannot be parsed.
7274 -> HakyllAction Context Context
73−renderDate key format defaultValue = renderValue "path" key renderDate'
75+renderDate = renderDateWithLocale defaultTimeLocale
76+
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
79+-- 'renderDate'.
80+--
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 =
87+ renderValue "path" key renderDate'
7488 where
7589 renderDate' filePath = fromMaybe defaultValue $ do
7690 let dateString = substituteRegex "^([0-9]*-[0-9]*-[0-9]*).*" "\\1"
@@ -78,7 +92,7 @@ renderDate key format defaultValue = renderValue "path" key renderDate'
7892 time <- parseTime defaultTimeLocale
7993 "%Y-%m-%d"
8094 dateString :: Maybe UTCTime
81− return $ formatTime defaultTimeLocale format time
95+ return $ formatTime locale format time
8296
8397-- | Change the extension of a file. This is only needed when you want to
8498-- render, for example, mardown to @.php@ files instead of @.html@ files.