2019-02-04 22:50:41 +01:00
|
|
|
{-# LANGUAGE NamedFieldPuns #-}
|
2019-02-17 19:52:28 +01:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
{-# LANGUAGE FlexibleContexts #-}
|
2019-02-04 22:50:41 +01:00
|
|
|
module ArticlesList (
|
|
|
|
ArticlesList(..)
|
2020-03-25 19:47:28 +01:00
|
|
|
, description
|
2020-05-08 15:51:25 +02:00
|
|
|
, getArticles
|
|
|
|
, otherURL
|
|
|
|
, rssLinkTexts
|
2019-02-04 22:50:41 +01:00
|
|
|
) where
|
|
|
|
|
|
|
|
import Article (Article)
|
2020-05-08 15:51:25 +02:00
|
|
|
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)
|
2019-02-19 21:48:55 +01:00
|
|
|
import Files (absoluteLink)
|
2020-05-08 15:51:25 +02:00
|
|
|
import Pretty ((.$))
|
2019-02-04 22:50:41 +01:00
|
|
|
import System.FilePath.Posix ((</>))
|
|
|
|
|
|
|
|
data ArticlesList = ArticlesList {
|
2020-05-08 15:51:25 +02:00
|
|
|
full :: Bool
|
|
|
|
, collection :: Collection
|
2019-02-04 22:50:41 +01:00
|
|
|
}
|
|
|
|
|
2020-05-08 15:51:25 +02:00
|
|
|
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
|
2019-02-04 22:50:41 +01:00
|
|
|
|
2020-05-08 15:51:25 +02:00
|
|
|
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
|
|
|
|
2020-05-08 15:51:25 +02: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
|
2020-05-08 15:51:25 +02:00
|
|
|
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
|