@@ -34,7 +34,7 @@ module Hakyll.Web.Template.Context
3434--------------------------------------------------------------------------------
3535import Control.Applicative (Alternative (..))
3636import Control.Monad (msum)
37−import Data.List (intercalate)
37+import Data.List (intercalate, tails)
3838#if MIN_VERSION_base(4,9,0)
3939import Data.Semigroup (Semigroup (..))
4040#endif
@@ -269,6 +269,12 @@ titleField = mapContext takeBaseName . pathField
269269-- that begins with @yyyy-mm-dd@ . For example:
270270-- @folder//yyyy-mm-dd-title//dist//main.extension@ .
271271-- In case of multiple matches, the rightmost one is used.
272+--
273+-- As another alternative, if none of the above matches, and the file has a
274+-- path which contains nested directories specifying a date, then that date
275+-- will be used. In other words, if the path is of the form
276+-- @**//yyyy//mm//dd//**//main.extension@ .
277+-- As above, in case of multiple matches, the rightmost one is used.
272278
273279dateField :: String -- ^ Key in which the rendered date should be placed
274280 -> String -- ^ Format to use on the date
@@ -305,7 +311,8 @@ getItemUTC locale id' = do
305311 maybe empty' return $ msum $
306312 [tryField "published" fmt | fmt <- formats] ++
307313 [tryField "date" fmt | fmt <- formats] ++
308− [parseTime' "%Y-%m-%d" $ intercalate "-" $ take 3 $ splitAll "-" fnCand | fnCand <- reverse paths]
314+ [parseTime' "%Y-%m-%d" $ intercalate "-" $ take 3 $ splitAll "-" fnCand | fnCand <- reverse paths] ++
315+ [parseTime' "%Y-%m-%d" $ intercalate "-" $ fnCand | fnCand <- map (take 3) $ reverse . tails $ paths]
309316 where
310317 empty' = fail $ "Hakyll.Web.Template.Context.getItemUTC: " ++
311318 "could not parse time for " ++ show id'