Wayne Chang
2017-03-19 16:46:43 UTC
Hi,
I'm trying to add a Related Posts section to my blog...I'm running into
circular dependency errors from the item compiler as I try to link two
posts to each other.
refer to Post 2, but at this point, Post 2 can no longer refer to Post 1
without creating a circular dependency.
I'm considering:
- Loading Post metadata in a way that sneaks past the compiler's
dependency graph
- Creating a post/meta folder containing only files with copied metadata
per post, allowing for a DAG
Neither of these feel ideal. Any thoughts?
Thanks in advance for any responses! I can do a short write-up on this
after to help those with this problem in the future.
Best,
- Wayne
I'm trying to add a Related Posts section to my blog...I'm running into
circular dependency errors from the item compiler as I try to link two
posts to each other.
---
title: My Post Title
teaser: Something eye-catching that will make the user click
bannerImageUrl: /images/my-post.png
- "2017-01-02-my-second-post.md"
- "2017-01-07-my-third-post.md"
---
match "posts/*" $ do
route $ cleanRoute
compile $ do
id' <- getUnderlying
metadata <- getMetadata id'
let relatedPostsNames = fromMaybe [] $ lookupStringList
"relatedPosts" metadata
let relatedPostsPaths = map (fromFilePath . ("posts/"++))
relatedPostsNames
posts <- loadAll $ fromList relatedPostsPaths
let mHasRelatedPosts = (if null posts then mempty else
constField "hasRelatedPosts" "True")
let taggedPostCtx =
mHasRelatedPosts
`mappend`
listField "posts" postCtx (return posts)
`mappend`
constField "postListingTitle" "Related Posts"
`mappend`
postCtxWithTags tags
pandocCompiler
It works except for the problem above. We can first have Post 1 cantitle: My Post Title
teaser: Something eye-catching that will make the user click
bannerImageUrl: /images/my-post.png
- "2017-01-02-my-second-post.md"
- "2017-01-07-my-third-post.md"
---
match "posts/*" $ do
route $ cleanRoute
compile $ do
id' <- getUnderlying
metadata <- getMetadata id'
let relatedPostsNames = fromMaybe [] $ lookupStringList
"relatedPosts" metadata
let relatedPostsPaths = map (fromFilePath . ("posts/"++))
relatedPostsNames
posts <- loadAll $ fromList relatedPostsPaths
let mHasRelatedPosts = (if null posts then mempty else
constField "hasRelatedPosts" "True")
let taggedPostCtx =
mHasRelatedPosts
`mappend`
listField "posts" postCtx (return posts)
`mappend`
constField "postListingTitle" "Related Posts"
`mappend`
postCtxWithTags tags
pandocCompiler
= loadAndApplyTemplate "templates/post.html"
= taggedPostCtx
= loadAndApplyTemplate "templates/default.html"
= taggedPostCtx
= relativizeUrls
= taggedPostCtx
= loadAndApplyTemplate "templates/default.html"
= taggedPostCtx
= relativizeUrls
refer to Post 2, but at this point, Post 2 can no longer refer to Post 1
without creating a circular dependency.
I'm considering:
- Loading Post metadata in a way that sneaks past the compiler's
dependency graph
- Creating a post/meta folder containing only files with copied metadata
per post, allowing for a DAG
Neither of these feel ideal. Any thoughts?
Thanks in advance for any responses! I can do a short write-up on this
after to help those with this problem in the future.
Best,
- Wayne
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.