41 lines
1.1 KiB
Haskell
41 lines
1.1 KiB
Haskell
{-# LANGUAGE NamedFieldPuns #-}
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
{-# LANGUAGE FlexibleContexts #-}
|
|
module ArticlesList (
|
|
ArticlesList(..)
|
|
, otherUrl
|
|
, pageTitle
|
|
) where
|
|
|
|
import Article (Article)
|
|
import Blog (Blog(..), Wording(..), get)
|
|
import Control.Monad.Reader (MonadReader)
|
|
import Data.Text (Text, pack)
|
|
import Data.Text.Lazy (toStrict)
|
|
import Data.Text.Template (render)
|
|
import Pretty ((.$))
|
|
import System.FilePath.Posix ((</>))
|
|
|
|
data ArticlesList = ArticlesList {
|
|
tagged :: Maybe String
|
|
, full :: Bool
|
|
, featured :: [Article]
|
|
}
|
|
|
|
otherUrl :: ArticlesList -> String
|
|
otherUrl (ArticlesList {full, tagged}) =
|
|
if full
|
|
then url tagged
|
|
else url tagged </> "all.html"
|
|
where
|
|
url = maybe "/" ("/" </>)
|
|
|
|
pageTitle :: (MonadReader Blog m) => ArticlesList -> m Text
|
|
pageTitle (ArticlesList {full, tagged}) = do
|
|
template <- Blog.get $wording.$(if full then allTaggedPage else latestTaggedPage)
|
|
untagged <- Blog.get $wording.$(if full then allPage else latestPage)
|
|
return $ maybe untagged (toStrict . render template . tag) tagged
|
|
where
|
|
tag :: String -> Text -> Text
|
|
tag t = \"tag" -> pack t
|