2016-07-09 6 views
0

インデックスページに「リンク」フィールドを定義しようとすると、linksフィールドを作成しても、[ERROR] Missing field $links$ in context for item index.htmlというエラーが発生しました。 (少なくとも私は持っていると確信しています...)Hakyllで任意のフィールドを定義できないのはなぜですか?

-- site.hs 
main = hakyll $ do 

    match "index.html" $ do 
     route idRoute 
     compile $ do 
      links <- loadAll "links/*" 
      let indexCtx = 
        listField "links" linkCtx (return links) `mappend` 
        constField "title" "Home"    `mappend` 
        defaultContext 

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

    match "templates/*" $ compile templateBodyCompiler 


linkCtx :: Context String 
linkCtx = 
    field "link" $ \item -> return (itemBody item) 
    defaultContext 

-- index.html 
<h2>Links</h2> 
$partial("templates/link-list.html")$ 

-- templates/link-list.html 
<ul> 
    $for(links)$ 
     $link$ 
    $endfor$ 
</ul> 

-- links/behance.markdown 
--- 
title: Behance 
--- 

[Behance](https://www.behance.net/laylow) 

答えて

1

あなたのコードを試してみると、私はそのようなエラーはありません。代わりに私はlinkCtxから型エラーを取得します。 point-free formでラムダを置き換え、

linkCtx = 
    field "link" (\item -> return (itemBody item)) `mappend` 
    defaultContext 

以上の慣用的に:それは次のように修正することができます。

linkCtx = 
    field "link" (return . itemBody) `mappend` 
    defaultContext 

また、いくつかのアイテムを読み込む場合は、最初に一致させる必要があります。ハキルルはその存在を知っています。使用してsite.hsを再構築し、上記の変更を行った後

match "links/*" $ compile pandocCompiler 

stack buildとリンクのリストは、index.htmlの中に返信用

+0

おかげでレンダリングされます。残念ながら、コードを導入しても何も変更されません。これは、私が間違ったことをしていると私に信じさせる原因になります。 [this](http://blog.gmane.org/gmane.comp.lang.haskell.hakyll/month=20130601)の問題が発生している可能性がありますか? – pdoherty926

+1

rebuildingの出力を '-v'引数で共有できますか(例えば' stack exec-site rebuild -v') –

+0

[こちら](https://gist.github.com/ethagnawl/e849ed70639c8b87630418efc8fbdc40)その出力コマンドと[最新コード](https://github.com/ethagnawl/peterdohertys.website)を参照してください。再度、感謝します。 – pdoherty926

関連する問題