1

我正在将我的博客移至 hakyll。

在我在索引页面的网页设计中,有水平行,每行有 3 个帖子预览。Css/js 是这样制作的,我最好不要用我拥有的所有帖子填充这一行,让它们自动流动,但我最好将帖子列表剪切为每个帖子中的 3 个帖子块并生成单独的行每个块有 3 个帖子。

所以而不是

- row
   - col-sm-4 - col-sm-4 - col-sm-4
   - col-sm-4 ...

我希望有

- row
   - col-sm-4 - col-sm-4 - col-sm-4
- row
   - col-sm-4 - col-sm-4 - col-sm-4
...

在我的site.hs我有很典型的

match "blog.html" $ do
  route cleanRoute
  compile $ do
    posts <- recentFirst =<< loadAll "posts/**"
    let indexCtx =
            listField "posts" postCtxWithCat (return posts) `mappend`
            favCtx

    getResourceBody
      >>= applyAsTemplate indexCtx
      >>= loadAndApplyTemplate "templates/default.html" indexCtx
      >>= relativizeUrls
      >>= cleanIndexUrls

现在我想将帖子削减为 3 个。

    posts <- recentFirst =<< loadAll "posts/**"
    let postsBy3 = chunksOf 3 posts -- from split package

但是如何将其postsBy3 :: [[Item String]]进一步提供给模板以及如何使用它......是一个大问题。

只是在做

listField "postsBy3" postCtxWithCat (return postsBy3) `mappend`...

显然是类型不匹配。

卡住。

4

0 回答 0