如何在我的安装中包含post teasers?

时间:2017-01-23 07:51:31

标签: haskell scope hakyll

我正在关注the official instructions on the Hakyll site以便在我的网站上启动并运行预告片。不幸的是,我遇到了麻烦,而且说明没有多大帮助。

我在此代码段中引用的item值出现超出范围的错误:

loadAndApplyTemplate
     "template/postitem.html"
     (teaserField "teaser" "content" <> defaultContext)
     item

将其嵌入我的site.hs时。为了重现性,侧面说明,<>运算符的来源也不清楚;这需要导入一个Literate Haskell模块。

完全不清楚这个item的引用来自何处,因为它是一个相当常见的词,即使在我的findgrep上使用item,我也必须筛选数千个结果机。

我应该声明或导入哪些内容才能访问private static void Ticker() { float previousAmount = 0.0; while (true) { const string uri = @"https://api.coinmarketcap.com/v1/ticker/ethereum/"; var client = new WebClient(); var content = client.DownloadString(uri); var results = JsonConvert.DeserializeObject<List<CoinApi>>(content); float currentAmount = results[0].price_usd; if (currentAmount < previousAmount ) { Console.WriteLine("Ammount is lower than the last time."); } else if (currentAmount > previousAmount ) { Console.WriteLine("The amount is higher than the last time."); } else if (currentAmount == previousAmount) { Console.WriteLine("The amount hasnt changed since the last time we scanned."); } previousAmount = currentAmount; } }

1 个答案:

答案 0 :(得分:2)

教程页面不是一个完整的例子。 不是对某些功能的引用。它只是Item的占位符名称。通常,您可以从pandocCompiler或其中一个many other "compilers"获取。在此示例中,loadAndApplyTemplate就像其他任何使用它一样。唯一的区别是item将绑定到模板中的预告文字。

那就是说,这并不是一个很好的例子,因为你通常想在列出多个帖子的页面上使用预告文本。这可能涉及使用listField来创建您将在模板中迭代的帖子集合。例如,这是我的索引页面的规则:

$teaser$

&#34;项目&#34;在这种情况下,getResourceBody返回的是match "index.html" $ do route idRoute compile $ do posts <- fmap (take indexRecentPostCount) . recentFirst =<< loadAllSnapshots postsPattern "postContent" let indexCtx = constField "title" "Home" <> baseCtx getResourceBody >>= applyAsTemplate (listField "posts" (teaserField "teaser" "postContent" <> postCtx) (return posts) <> indexCtx) >>= loadAndApplyDefaultTemplate indexCtx >>= relativizeUrls 的正文。这会将index.html绑定到帖子列表。忽略元数据,我的$posts$只是:

index.html

$for(posts)$ $partial("templates/teaser.html")$ $endfor$ 然后绑定在$teaser$模板中。