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(..)
|
|
|
|
, otherUrl
|
|
|
|
, pageTitle
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Article (Article)
|
2019-08-27 13:23:17 +02:00
|
|
|
import Blog (Blog(..), get)
|
|
|
|
import Blog.Wording (render)
|
2019-02-17 19:52:28 +01:00
|
|
|
import Control.Monad.Reader (MonadReader)
|
|
|
|
import Data.Text (Text, pack)
|
2019-02-19 21:48:55 +01:00
|
|
|
import Files (absoluteLink)
|
2019-02-04 22:50:41 +01:00
|
|
|
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
|
2019-02-19 21:48:55 +01:00
|
|
|
otherUrl (ArticlesList {full, tagged}) = absoluteLink $
|
|
|
|
(if full then id else (</> "all.html")) $ maybe "" id tagged
|
2019-02-04 22:50:41 +01:00
|
|
|
|
2019-02-17 19:52:28 +01:00
|
|
|
pageTitle :: (MonadReader Blog m) => ArticlesList -> m Text
|
2019-08-27 13:23:17 +02:00
|
|
|
pageTitle (ArticlesList {full, tagged}) = title (full, tagged) <$> Blog.get wording
|
2019-02-17 19:52:28 +01:00
|
|
|
where
|
2019-08-27 13:23:17 +02:00
|
|
|
title (True, Nothing) = render "allPage" []
|
|
|
|
title (True, Just tag) = render "allTaggedPage" [("tag", pack tag)]
|
|
|
|
title (False, Nothing) = render "latestPage" []
|
|
|
|
title (False, Just tag) = render "latestTaggedPage" [("tag", pack tag)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|