From 41e7b8cf18ae29a57b518437c706a7c7c377fc15 Mon Sep 17 00:00:00 2001 From: Taeer Bar-Yam Date: Sat, 25 May 2019 02:28:34 -0700 Subject: Add option to specify date in directory structure --- lib/Hakyll/Web/Template/Context.hs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'lib') 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' -- cgit v1.2.3