Open CrystalSplitter opened 2 months ago
Two updates on this:
render<Feed>WithTemplates
calls, which I'll detail below. I don't know if it's the idiomatic way to go about this, but it's reasonably clean, and it reveals the runtime type problem fairly clearly.atom_item_template.xml
, re-running without cleaning the cache gets me to the second error, and re-running a third time gets me the third error. It's not cleaning the cache after the error, so it progresses to the next failure mode on-reruns.The underlying problem was, of course, load
ing a file as an Item String
makes it a String
in the Store. Later converting it to a Template
by passing it to renderAtomWithTemplates
doesn't change the type in the Store. When it it looks up atomItemTemplate
expecting a Template
, it instead gets [Char]
. This makes sense once you remember load
puts whatever is loaded in to the Store
. What I did not expect was that it also stores its type there. It makes sense given how Hakyll works, but it only clicked for me now after walking through with the debugger.
-- | Generate the Atom Feed
atomFeedRules
:: (HK.Identifier, HK.FeedConfiguration)
-- ^ Feed name and the feed configuration to use.
-> HK.Pattern
-- ^ File pattern to match entries for the atom feed.
-> HK.Rules ()
atomFeedRules (feedName, feedConf) pattern = HK.create [feedName] $ do
HK.route HK.idRoute
HK.compile $ do
(HK.Item _atPath atomTemplate) <- HK.load "templates/atom_template.xml"
(HK.Item _aitPath atomItemTemplate) <- HK.load "templates/atom_item_template.xml"
allPosts <- HK.loadAllSnapshots pattern feedSnapshot
posts <- mapM HK.relativizeUrls . take 10 =<< HK.recentFirst allPosts
let feedCtx =
postCtx
<> HK.field "summary" sanitiseItemHTML
<> HK.bodyField "content"
HK.renderAtomWithTemplates atomTemplate atomItemTemplate feedConf feedCtx posts
where
sanitiseItemHTML :: HK.Item String -> HK.Compiler String
sanitiseItemHTML item =
pure
. TagSoup.innerText
. TagSoup.parseTags
. HK.itemBody
$ item
So up to maintainers to close this out as "user error", or if you want to write some documentation examples for usage of renderRSSWithTemplates
or renderAtomWithTemplates
.
I would still recommend "fixing" the atom template to at least pass the "description" into the "
Hello! This is potentially a documentation issue, or an issue that's been around since 2019 (hakyll version 4.13.0.0)?
I'm trying to figure out how to pass
Template
types torenderAtomWithTemplates
(though I suspect this also happens withrenderRSSWithTemplates
).The following compiles fine...
However, when actually running this, one of three things happen, and which happens seems to be nondeterministic.
It doesn't build the site, and produces this error:
It also doesn't build the site, but complains about
atom_template.xml
instead.It DOES build, but it generates an invalid
atom_template.xml
??? This is by far the most confusing to me. This produces a binary file, with some control characters and some bits of XML:No idea what's happening here, but this seems to be a bug?
I can't find anyone who's using
renderAtomWithTemplates
orrenderRSSWithTemplates
to work, so I'm extremely curious how to use it. But also, this appears to be some bug.This was all spurred on by the fact that I noticed that the atom feeds incorrectly put the "description" field into the atom
<summary>
element instead of the atom<content>
element. (See RFC4287)