readingTimeField :: String -> Snapshot -> Context String
readingTimeField key snapshot =
field key calculate
where
calculate :: Item String -> Compiler String
calculate item = do
body <- loadSnapshotBody (itemIdentifier item) snapshot
pure $ withTagList acc body
acc ts = [TagText $ show $ time ts]
-- M. Brysbaert, Journal of Memory and Language (2009) vol 109. DOI: 10.1016/j.jml.2019.104047
time ts = foldr count 0 ts `div` 238
count (TagText s) n = n + length (words s)
count _ n = n
This generates a really weird error saying that the template depends on itself (Hakyll):
> [ERROR] Hakyll.Core.Runtime.pickAndChase: Dependency cycle detected: atom.xml depends on [(posts/2023-01-26-elm-to-haskell-part1.md,"content"),(posts/2023-02-23-elm-to-haskell-part2.md,"content"),(posts/2023-02-24-egghead-elm-ui-course.md,"content"),(posts/2023-03-01-elm-to-haskell-part3.md,"content")], index.html depends on [(posts/2023-01-26-elm-to-haskell-part1.md,"_final"),(posts/2023-02-23-elm-to-haskell-part2.md,"_final"),(posts/2023-02-24-egghead-elm-ui-course.md,"_final"),(posts/2023-03-01-elm-to-haskell-part3.md,"_final")], posts/2023-01-26-elm-to-haskell-part1.md depends on [(posts/2023-01-26-elm-to-haskell-part1.md,"content"),(templates/post.html,"_final")], posts/2023-02-23-elm-to-haskell-part2.md depends on [(posts/2023-02-23-elm-to-haskell-part2.md,"content"),(templates/post.html,"_final")], posts/2023-02-24-egghead-elm-ui-course.md depends on [(posts/2023-02-24-egghead-elm-ui-course.md,"content"),(templates/post.html,"_final")], posts/2023-03-01-elm-to-haskell-part3.md depends on [(posts/2023-03-01-elm-to-haskell-part3.md,"content"),(templates/post.html,"_final")], rss.xml depends on [(posts/2023-01-26-elm-to-haskell-part1.md,"content"),(posts/2023-02-23-elm-to-haskell-part2.md,"content"),(posts/2023-02-24-egghead-elm-ui-course.md,"content"),(posts/2023-03-01-elm-to-haskell-part3.md,"content")], sitemap.xml depends on [(posts/2023-01-26-elm-to-haskell-part1.md,"_final"),(posts/2023-02-23-elm-to-haskell-part2.md,"_final"),(posts/2023-02-24-egghead-elm-ui-course.md,"_final"),(posts/2023-03-01-elm-to-haskell-part3.md,"_final")]
For full logs, run 'nix log /nix/store/2hamrx99pbhq4r7f28457xh28w4hxgkz-website.drv'.
Should investigate more but apparently the solution is not trivial 🤔
Still could not use this Haskell code:
This generates a really weird error saying that the template depends on itself (Hakyll):
Should investigate more but apparently the solution is not trivial 🤔
(cc: @rpearce @jaspervdj)