summaryrefslogtreecommitdiff
path: root/lib/Hakyll
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Hakyll')
-rw-r--r--lib/Hakyll/Web/Template/Context.hs11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/Hakyll/Web/Template/Context.hs b/lib/Hakyll/Web/Template/Context.hs
index 0d71386..8038253 100644
--- a/lib/Hakyll/Web/Template/Context.hs
+++ b/lib/Hakyll/Web/Template/Context.hs
@@ -34,7 +34,7 @@ module Hakyll.Web.Template.Context
--------------------------------------------------------------------------------
import Control.Applicative (Alternative (..))
import Control.Monad (msum)
-import Data.List (intercalate)
+import Data.List (intercalate, tails)
#if MIN_VERSION_base(4,9,0)
import Data.Semigroup (Semigroup (..))
#endif
@@ -269,6 +269,12 @@ titleField = mapContext takeBaseName . pathField
-- that begins with @yyyy-mm-dd@ . For example:
-- @folder//yyyy-mm-dd-title//dist//main.extension@ .
-- In case of multiple matches, the rightmost one is used.
+--
+-- As another alternative, if none of the above matches, and the file has a
+-- path which contains nested directories specifying a date, then that date
+-- will be used. In other words, if the path is of the form
+-- @**//yyyy//mm//dd//**//main.extension@ .
+-- As above, in case of multiple matches, the rightmost one is used.
dateField :: String -- ^ Key in which the rendered date should be placed
-> String -- ^ Format to use on the date
@@ -305,7 +311,8 @@ getItemUTC locale id' = do
maybe empty' return $ msum $
[tryField "published" fmt | fmt <- formats] ++
[tryField "date" fmt | fmt <- formats] ++
- [parseTime' "%Y-%m-%d" $ intercalate "-" $ take 3 $ splitAll "-" fnCand | fnCand <- reverse paths]
+ [parseTime' "%Y-%m-%d" $ intercalate "-" $ take 3 $ splitAll "-" fnCand | fnCand <- reverse paths] ++
+ [parseTime' "%Y-%m-%d" $ intercalate "-" $ fnCand | fnCand <- map (take 3) $ reverse . tails $ paths]
where
empty' = fail $ "Hakyll.Web.Template.Context.getItemUTC: " ++
"could not parse time for " ++ show id'