module Rules.Blog.Paginate.TaggedPosts (
    build
) where

import           Control.Monad.Trans       (MonadTrans (..))
import           Hakyll

import           Config.Blog               (BlogConfig (..))
import           Rules.Blog.ListPage       (ListPageOpts, listPage)
import           Rules.Blog.Paginate.Utils
import           Rules.Blog.Type
import qualified Vendor.FontAwesome        as FA

build :: FA.FontAwesomeIcons
    -> Tags
    -> ListPageOpts
    -> BlogConfReader n Rules ()
build :: forall (n :: * -> *).
FontAwesomeIcons
-> Tags -> ListPageOpts -> BlogConfReader n Rules ()
build FontAwesomeIcons
faIcons Tags
tags ListPageOpts
listPageOpts = do
    [Identifier] -> Rules [[Identifier]]
grouper' <- BlogConfReader n Rules ([Identifier] -> Rules [[Identifier]])
forall (m :: * -> *) (f :: * -> *) (n :: * -> *).
(Monad m, MonadMetadata f, MonadFail f) =>
BlogConfReader n m ([Identifier] -> f [[Identifier]])
grouper
    FilePath -> PageNumber -> Identifier
makeId' <- (BlogConfig n -> FilePath -> FilePath)
-> BlogConfReader n Rules (FilePath -> PageNumber -> Identifier)
forall (n :: * -> *) (m :: * -> *) a.
Monad n =>
(BlogConfig m -> a -> FilePath)
-> BlogConfReader m n (a -> PageNumber -> Identifier)
makeId BlogConfig n -> FilePath -> FilePath
forall (m :: * -> *). BlogConfig m -> FilePath -> FilePath
blogTagPagesPath
    Rules () -> BlogConfReader n Rules ()
forall (m :: * -> *) a.
Monad m =>
m a -> ReaderT (BlogConfig n) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Rules () -> BlogConfReader n Rules ())
-> Rules () -> BlogConfReader n Rules ()
forall a b. (a -> b) -> a -> b
$ Tags -> (FilePath -> Pattern -> Rules ()) -> Rules ()
tagsRules Tags
tags ((FilePath -> Pattern -> Rules ()) -> Rules ())
-> (FilePath -> Pattern -> Rules ()) -> Rules ()
forall a b. (a -> b) -> a -> b
$ \FilePath
tag Pattern
pat ->
        let title' :: FilePath
title' = FilePath -> FilePath -> FilePath
title FilePath
"Tagged" FilePath
tag
        in ([Identifier] -> Rules [[Identifier]])
-> Pattern -> (PageNumber -> Identifier) -> Rules Paginate
forall (m :: * -> *).
MonadMetadata m =>
([Identifier] -> m [[Identifier]])
-> Pattern -> (PageNumber -> Identifier) -> m Paginate
buildPaginateWith [Identifier] -> Rules [[Identifier]]
grouper' Pattern
pat (FilePath -> PageNumber -> Identifier
makeId' FilePath
tag)
            Rules Paginate -> (Paginate -> Rules ()) -> Rules ()
forall a b. Rules a -> (a -> Rules b) -> Rules b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Maybe FilePath
-> FontAwesomeIcons -> Tags -> ListPageOpts -> Paginate -> Rules ()
listPage (FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just FilePath
title') FontAwesomeIcons
faIcons Tags
tags ListPageOpts
listPageOpts