Skip to content

Commit

Permalink
refactoring for the index page
Browse files Browse the repository at this point in the history
  • Loading branch information
falgon committed Aug 29, 2023
1 parent a5db067 commit c25607d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
3 changes: 2 additions & 1 deletion roki-web.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: 8e5e07d8a2ab1d682d23a39c9b0850d6d6957ef58ecf7effca71efc93dfa5902
-- hash: 86e256f02b92abdb8ba22b3caaafe86de11e025bd67fac4055916ce32295eb3c

name: roki-web
version: 1.0.0.0
Expand Down Expand Up @@ -58,6 +58,7 @@ library
Rules.Blog.Feed.RSS
Rules.Blog.Feed.Utils
Rules.Blog.Footer
Rules.Blog.Index
Rules.Blog.ListPage
Rules.Blog.Paginate.MonthlyPosts
Rules.Blog.Paginate.TaggedPosts
Expand Down
12 changes: 4 additions & 8 deletions src/Rules/Blog/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Control.Monad.Extra (mconcatMapM)
import Control.Monad.Reader (ask, asks)
import Control.Monad.Trans (MonadTrans (..))
import Hakyll hiding
(FeedConfiguration (..),
(FeedConfiguration (..),
renderAtom, renderRss)
import System.FilePath ((</>))

Expand All @@ -24,14 +24,14 @@ import Rules.Blog.EachPostSeries
import qualified Rules.Blog.Feed.Atom as Atom
import qualified Rules.Blog.Feed.RSS as RSS
import Rules.Blog.Footer (appendFooter)
import Rules.Blog.ListPage (ListPageOpts (..), listPage)
import qualified Rules.Blog.Index as Index
import Rules.Blog.ListPage (ListPageOpts (..))
import qualified Rules.Blog.Paginate.MonthlyPosts as MonthlyPosts
import qualified Rules.Blog.Paginate.TaggedPosts as TaggedPosts
import qualified Rules.Blog.Paginate.YearlyPosts as YearlyPosts
import qualified Rules.Blog.Search as Search
import Rules.Blog.Type
import Utils (absolutizeUrls,
makePageIdentifier,
modifyExternalLinkAttr)
import qualified Vendor.FontAwesome as FA
import qualified Vendor.KaTeX as KaTeX
Expand Down Expand Up @@ -81,7 +81,6 @@ blogRules faIcons = do
route $ gsubRoute (contentsRoot <> "/") (const mempty)
compile copyFileCompiler

peNum <- asks blogPageEntriesNum
listPageOpts <- ListPageOpts
<$> BlogCtx.title
<*> asks blogName
Expand All @@ -104,10 +103,7 @@ blogRules faIcons = do
monthlyArchives <- MonthlyPosts.build faIcons tags listPageOpts

-- the index page of blog
lift $ listPage Nothing faIcons tags listPageOpts =<<
let grouper = fmap (paginateEvery peNum) . sortRecentFirst
makeId = makePageIdentifier (blogTitle </> "index.html")
in buildPaginateWith grouper (blogEntryPattern bc) makeId
Index.build faIcons tags listPageOpts

-- footer
pCtxForFooter <- postCtx tags
Expand Down
26 changes: 26 additions & 0 deletions src/Rules/Blog/Index.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module Rules.Blog.Index (
build
) where

import Control.Monad.Reader (asks, lift)
import Hakyll
import System.FilePath ((</>))

import Config.Blog (BlogConfig (..))
import Rules.Blog.ListPage
import Rules.Blog.Type
import Utils (makePageIdentifier)
import qualified Vendor.FontAwesome as FA

build :: FA.FontAwesomeIcons
-> Tags
-> ListPageOpts
-> BlogConfReader m Rules ()
build faIcons tags opts = do
makeId <- asks $ makePageIdentifier . (</> "index.html") . blogName
f <- asks $ fmap . paginateEvery . blogPageEntriesNum
ep <- asks blogEntryPattern
lift $ listPage Nothing faIcons tags opts =<<
let grouper = f . sortRecentFirst
in buildPaginateWith grouper ep makeId

0 comments on commit c25607d

Please sign in to comment.