@@ -33,7 +33,7 @@ import qualified Data.Map as M
3333import Data.Monoid (Monoid (..))
3434import Data.Time.Clock (UTCTime (..))
3535import Data.Time.Format (formatTime, parseTime)
36−import System.FilePath (takeBaseName, takeFileName)
36+import System.FilePath (takeBaseName, splitDirectories)
3737import System.Locale (TimeLocale, defaultTimeLocale)
3838
3939
@@ -218,7 +218,11 @@ titleField = mapContext takeBaseName . pathField
218218-- Alternatively, when the metadata has a field called @path@ in a
219219-- @folder/yyyy-mm-dd-title.extension@ format (the convention for pages)
220220-- and no @published@ metadata field set, this function can render
221−-- the date.
221+-- the date. This pattern matches the file name or directory names
222+-- that begins with @yyyy-mm-dd@ . For example:
223+-- @folder//yyyy-mm-dd-title//dist//main.extension@ .
224+-- In case of multiple matches, the rightmost one is used.
225+
222226dateField :: String -- ^ Key in which the rendered date should be placed
223227 -> String -- ^ Format to use on the date
224228 -> Context a -- ^ Resulting context
@@ -249,12 +253,12 @@ getItemUTC :: MonadMetadata m
249253getItemUTC locale id' = do
250254 metadata <- getMetadata id'
251255 let tryField k fmt = M.lookup k metadata >>= parseTime' fmt
252− fn = takeFileName $ toFilePath id'
256+ paths = splitDirectories $ toFilePath id'
253257
254258 maybe empty' return $ msum $
255259 [tryField "published" fmt | fmt <- formats] ++
256260 [tryField "date" fmt | fmt <- formats] ++
257− [parseTime' "%Y-%m-%d" $ intercalate "-" $ take 3 $ splitAll "-" fn]
261+ [parseTime' "%Y-%m-%d" $ intercalate "-" $ take 3 $ splitAll "-" fnCand | fnCand <- reverse paths]
258262 where
259263 empty' = fail $ "Hakyll.Web.Template.Context.getItemUTC: " ++
260264 "could not parse time for " ++ show id'