{-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE FlexibleContexts #-} module ArticlesList ( ArticlesList(..) , description , getArticles , otherURL , ArticlesList.path , rssLinkTexts ) where import Article (Article) import Blog (Blog(..), Renderer, Skin(..), template) import Collection (Collection(..)) import Control.Monad.Reader (MonadReader, asks) import Data.Text (Text, pack) import Pretty ((.$)) data ArticlesList = ArticlesList { full :: Bool , collection :: Collection } getArticles :: MonadReader Blog m => ArticlesList -> m [Article] getArticles (ArticlesList {full, collection = Collection {featured}}) = do limit <- take <$> (asks $skin.$previewArticlesCount) return $ if full then featured else limit featured otherURL :: ArticlesList -> FilePath otherURL (ArticlesList {full}) = if full then "." else "all.html" description :: Renderer m => ArticlesList -> m Text description (ArticlesList {full, collection}) = template page . environment $ tag collection where page = if full then "allPage" else "latestPage" environment = maybe [] $ \value -> [("tag", pack value)] rssLinkTexts :: Renderer m => ArticlesList -> m (Text, Text) rssLinkTexts (ArticlesList {collection}) = do text <- template "rssLink" [] title <- template "rssTitle" environment return (text, title) where environment = maybe [] (\v -> [("tag", pack v)]) $ tag collection path :: ArticlesList -> FilePath path = maybe "" id . tag . collection