diff options
author | Taeer Bar-Yam <Radvendii@users.noreply.github.com> | 2019-05-25 02:28:34 -0700 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2019-05-25 11:28:34 +0200 |
commit | 41e7b8cf18ae29a57b518437c706a7c7c377fc15 (patch) | |
tree | 12fe0d294acbeccbe8706b11da6b22425c9d2507 /lib/Hakyll/Web | |
parent | 29c453dcf7f513236a94a8fe80f75041c07c1d1a (diff) | |
download | hakyll-41e7b8cf18ae29a57b518437c706a7c7c377fc15.tar.gz |
Add option to specify date in directory structure
Diffstat (limited to 'lib/Hakyll/Web')
-rw-r--r-- | lib/Hakyll/Web/Template/Context.hs | 11 |
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' |