hablo/src/ArticlesList.hs

49 lines
1.5 KiB
Haskell
Raw Normal View History

{-# LANGUAGE NamedFieldPuns #-}
2019-02-17 19:52:28 +01:00
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleContexts #-}
module ArticlesList (
ArticlesList(..)
2020-03-25 19:47:28 +01:00
, description
, getArticles
, otherURL
, rssLinkTexts
) where
import Article (Article)
import Blog (Blog(..), Renderer, Skin(..), template)
import Collection (Collection(..))
2020-03-25 19:47:28 +01:00
import Control.Monad.Reader (MonadReader, asks)
2019-02-17 19:52:28 +01:00
import Data.Text (Text, pack)
import Files (absoluteLink)
import Pretty ((.$))
import System.FilePath.Posix ((</>))
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 -> String
otherURL (ArticlesList {full, collection}) = absoluteLink $
(if full then id else (</> "all.html")) . maybe "" id $ tag collection
2020-03-25 19:47:28 +01:00
description :: Renderer m => ArticlesList -> m Text
description (ArticlesList {full, collection}) =
template page . environment $ tag collection
2019-02-17 19:52:28 +01:00
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