diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2013-01-16 11:08:49 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2013-01-16 11:08:49 +0100 |
commit | a71c9c6a120face7282ff91f2e0a5a9fde5dd37f (patch) | |
tree | 92a88fa1e1fccb7e87457d6238442f66e0c528cb /src/Hakyll | |
parent | 652ceb03f1185ad8d41e7a3b91f00e1064bdd4ba (diff) | |
download | hakyll-a71c9c6a120face7282ff91f2e0a5a9fde5dd37f.tar.gz |
Export getItemUTC for convenience
Diffstat (limited to 'src/Hakyll')
-rw-r--r-- | src/Hakyll/Web/Template/Context.hs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/Hakyll/Web/Template/Context.hs b/src/Hakyll/Web/Template/Context.hs index 7d359b4..fcb527a 100644 --- a/src/Hakyll/Web/Template/Context.hs +++ b/src/Hakyll/Web/Template/Context.hs @@ -14,6 +14,7 @@ module Hakyll.Web.Template.Context , titleField , dateField , dateFieldWith + , getItemUTC , modificationTimeField , modificationTimeFieldWith , missingField @@ -158,26 +159,29 @@ dateFieldWith :: TimeLocale -- ^ Output time locale -> String -- ^ Format to use on the date -> Context a -- ^ Resulting context dateFieldWith locale key format = field key $ \i -> do - time <- getUTC locale $ itemIdentifier i + time <- getItemUTC locale $ itemIdentifier i return $ formatTime locale format time -------------------------------------------------------------------------------- -- | Parser to try to extract and parse the time from the @published@ -- field or from the filename. See 'renderDateField' for more information. -getUTC :: TimeLocale -- ^ Output time locale - -> Identifier -- ^ Input page - -> Compiler UTCTime -- ^ Parsed UTCTime -getUTC locale id' = do +-- Exported for user convenience. +getItemUTC :: TimeLocale -- ^ Output time locale + -> Identifier -- ^ Input page + -> Compiler UTCTime -- ^ Parsed UTCTime +getItemUTC locale id' = do metadata <- getMetadata id' let tryField k fmt = M.lookup k metadata >>= parseTime' fmt fn = takeFileName $ toFilePath id' - maybe empty return $ msum $ + maybe empty' return $ msum $ [tryField "published" fmt | fmt <- formats] ++ [tryField "date" fmt | fmt <- formats] ++ [parseTime' "%Y-%m-%d" $ intercalate "-" $ take 3 $ splitAll "-" fn] where + empty' = compilerThrow $ "Hakyll.Web.Template.Context.getItemUTC: " ++ + "could not parse time for " ++ show id' parseTime' = parseTime locale formats = [ "%a, %d %b %Y %H:%M:%S UT" |