diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2012-11-20 21:57:15 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2012-11-20 21:57:15 +0100 |
commit | a97b74b0d2f72722cd86619c01878acb01aa5167 (patch) | |
tree | fbd34eff28e1f2defb1afc4d2334e8b37d3fc7bf /src/Hakyll/Web/Template | |
parent | b5adcb69d1cd26e613c5c56c85307050bb8297cf (diff) | |
download | hakyll-a97b74b0d2f72722cd86619c01878acb01aa5167.tar.gz |
Port page list module a bit
Diffstat (limited to 'src/Hakyll/Web/Template')
-rw-r--r-- | src/Hakyll/Web/Template/List.hs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/Hakyll/Web/Template/List.hs b/src/Hakyll/Web/Template/List.hs new file mode 100644 index 0000000..e8da74f --- /dev/null +++ b/src/Hakyll/Web/Template/List.hs @@ -0,0 +1,53 @@ +-------------------------------------------------------------------------------- +-- | Provides an easy way to combine several items in a list. The applications +-- are obvious: +-- +-- * A post list on a blog +-- +-- * An image list in a gallery +-- +-- * A sitemap +module Hakyll.Web.Template.List + ( applyTemplateList + , chronological + , recentFirst + ) where + + +-------------------------------------------------------------------------------- +import Data.List (sortBy) +import Data.Ord (comparing) +import System.FilePath (takeBaseName) + + +-------------------------------------------------------------------------------- +import Hakyll.Core.Compiler +import Hakyll.Core.Identifier +import Hakyll.Core.Item +import Hakyll.Web.Template +import Hakyll.Web.Template.Context + + +-------------------------------------------------------------------------------- +-- | Set a field of a page to a listing of pages +applyTemplateList :: Template + -> Context a + -> [Item a] + -> Compiler String +applyTemplateList tpl context items = do + items' <- mapM (applyTemplate tpl context) items + return $ concat $ map itemBody items' + + +-------------------------------------------------------------------------------- +-- | Sort pages chronologically. This function assumes that the pages have a +-- @year-month-day-title.extension@ naming scheme -- as is the convention in +-- Hakyll. +chronological :: [Item a] -> [Item a] +chronological = sortBy $ comparing $ takeBaseName . toFilePath . itemIdentifier + + +-------------------------------------------------------------------------------- +-- | The reverse of 'chronological' +recentFirst :: [Item a] -> [Item a] +recentFirst = reverse . chronological |