gpt4 book ai didi

haskell - 修改 Hakyll 示例站点

转载 作者:行者123 更新时间:2023-12-04 15:24:06 25 4
gpt4 key购买 nike

我希望修改下面的代码,这样,它不会生成指向网站上最新三篇文章的链接,而是完全复制文章的正文,就像在传统博客中一样。我有点难以理解下面发生了什么,以及必要的改变是什么。

match "index.html" $ do
route idRoute
compile $ do
let indexCtx = field "posts" $ \_ ->
postList $ fmap (take 3) . recentFirst

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

最佳答案

这并非完全无关紧要。第一步是引入 snapshots .

如教程中所述,这可确保您可以在索引中包含博客文章,而无需先将模板应用于 HTML。所以你会得到类似的东西:

match "posts/*" $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtx
>>= saveSnapshot "content"
>>= loadAndApplyTemplate "templates/default.html" postCtx
>>= relativizeUrls

现在,为了在索引页面上显示帖子,您将能够使用整个 $body$的帖子。为此,您只需更新 templates/post-item.html变成类似的东西:
<div>
<a href="$url$"><h2>$title$</h2></a>
$body$
</div>

关于haskell - 修改 Hakyll 示例站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15860444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com