-
Notifications
You must be signed in to change notification settings - Fork 409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
phantom snapshot dependency #317
Comments
Dependency tracking does not take snapshots into account, but it looks like this would be a rather straightforward extension -- I'll have a look at it. |
I think I fixed the issue. Would you be willing to test if the current master branch of Hakyll solves your issue? It works for the small example you provided but I'm curious if there are any larger instances. In any case, I think it should work. |
Nice feature! It works for me. |
Thanks for the fix, now I'm trying to use this new feature on the site I'm building. Meanwhile, if I omit the |
Final result of the compilation rule is also a snapshot with the name Kind regards, On Sat, 13 Dec, 2014 at 12:28 PM, wferi [email protected]
|
But doesn't |
Ah, indeed. |
As far as I understand, hakyll does not know what snapshots will be saved until it finishes processing the compile rule. You might even have something like {-# LANGUAGE OverloadedStrings #-}
import Hakyll
main :: IO ()
main = hakyll $ do
match "main.markdown" $ version "content" $
compile pandocCompiler
match "main.markdown" $ do
route $ setExtension "html"
compile $ do
id' <- setVersion (Just "content") `fmap` getUnderlying
loadBody id' >>= makeItem
>>= loadAndApplyTemplate "templates/nav.html" navCtx
match "templates/nav.html" $ compile templateCompiler
navCtx :: Context String
navCtx = listField "pages" defaultContext (loadAll $ "*.markdown" .&&. hasVersion "content") |
Well, I had a look at the version feature beforehand, but at this point we are getting too messy for the task. Especially in a language which can cope with self-references like structure = length structure:take 3 structure I mean, already by using snapshots, we're kludging something which Haskell has for free. {-# LANGUAGE OverloadedStrings #-}
import Hakyll
main :: IO ()
main = hakyll $ do
match "main.markdown" $ do
route $ setExtension "html"
compile $ pandocCompiler >>= loadAndApplyTemplate "templates/nav.html" navCtx
match "templates/nav.html" $ compile templateCompiler
navCtx :: Context String
navCtx = listField "pages" (urlField "url" :: Context String) (loadAll "*.markdown") Basically, I'd be good until I used anything generated by |
We can just add loadWithoutBody id' = Item id' () |
I finally managed to use this new feature for my purpose. The gist of the thing is: navCtx :: Identifier -> Context String
navCtx mainPage = listField "pages" (current <> defaultContext) mainPages <> defaultContext
where current = field "current" (\i -> if mainPage == itemIdentifier i then return "current" else fail "other")
mainPages = loadAllSnapshots ("*.html" .||. "*.markdown") "content"
>>= sortByM (fmap read . flip getMetadataField' "navPrio" . itemIdentifier :: Item a -> Compiler Int)
-- sortByM from Hakyll/Web/Template/List.hs
sortByM :: (Monad m, Ord k) => (a -> m k) -> [a] -> m [a]
sortByM f xs = liftM (map fst . sortBy (comparing snd)) $
mapM (\x -> liftM (x,) (f x)) xs
finalize :: Item String -> Compiler (Item String)
finalize i = do
id' <- getUnderlying
let mainPage | matches "media/*" id' = "media.html"
| otherwise = id'
loadAndApplyTemplate "templates/default.html" (navCtx mainPage) i
>>= relativizeUrls with using metadata blocks like
everywhere, even instead of calling
Btw. I find conditional fields rather awkward to use, what do I overlook? field "current" (return . (mainPage ==) . itemIdentifier) would be much more natural for me. |
You might find #311 useful regarding that. |
I released this as Hakyll 4.6.2.0. Thanks for the input! |
Why does building
give the
error? After all, the snapshot is taken before applying the template, so all should be linear.
Looks like dependency tracking does not handle snapshots. Or I'm mistaken. Could you provide a fix to either, please?
The text was updated successfully, but these errors were encountered: