hablo/src/ArticlesList.hs

46 lines
1.3 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
, otherUrl
2020-03-25 19:47:28 +01:00
, title
) where
import Article (Article)
2020-03-25 19:47:28 +01:00
import Blog (Blog(..))
import Blog.Wording (render)
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 System.FilePath.Posix ((</>))
data ArticlesList = ArticlesList {
tagged :: Maybe String
, full :: Bool
, featured :: [Article]
}
2019-02-06 12:57:57 +01:00
otherUrl :: ArticlesList -> String
otherUrl (ArticlesList {full, tagged}) = absoluteLink $
(if full then id else (</> "all.html")) $ maybe "" id tagged
2020-03-25 19:47:28 +01:00
title :: MonadReader Blog m => ArticlesList -> m String
title (ArticlesList {tagged}) = do
asks $ (\name -> maybe name ((name ++ " - ") ++) tagged) . name
description :: MonadReader Blog m => ArticlesList -> m Text
description (ArticlesList {full, tagged}) =
getDescription (full, tagged) <$> asks wording
2019-02-17 19:52:28 +01:00
where
2020-03-25 19:47:28 +01:00
getDescription (True, Nothing) = render "allPage" []
getDescription (True, Just tag) = render "allTaggedPage" [("tag", pack tag)]
getDescription (False, Nothing) = render "latestPage" []
getDescription (False, Just tag) =
render "latestTaggedPage" [("tag", pack tag)]