Discussion:
Pandoc + Templates = Challenge
l***@public.gmane.org
2013-09-24 22:08:50 UTC
Permalink
Greetings.

I am a Haskell noob playing around with hakyll.

I took the default site produced by hakyll-init and converted the
index.html to a index.markdown file. Not for any good reason, just to play
around. Here's the result: https://github.com/duk3luk3/hakylltestsite

Here's the code for the index.markdown:

match "index.markdown" $ do
route $ setExtension "html"
compile $ do
posts <- recentFirst =<< loadAll "posts/*"
let indexCtx =
listField "posts" postCtx (return posts) `mappend`
constField "title" "Home" `mappend`
defaultContext

getResourceBody
= applyAsTemplate indexCtx
= loadAndApplyTemplate "templates/default.html" indexCtx
= relativizeUrls
= return . renderPandoc
Nothing else was changed in site.hs.

The result is not pretty. I've tried putting the ">== return .
renderPandoc" in any place, and I've tried using PandocCompiler instead of
getResourceBody. It never gets rendered properly.

What am I missing? How do I make Pandoc play nice with templates?

Best regards
Luke
--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Jasper Van der Jeugt
2013-09-25 07:27:51 UTC
Permalink
Hey Luke!

The order you want is:

1. Load it as a string of just markdown

getResourceBody

2. Insert the post list. Note that this is an HTML string, which gets
interleaved in the markdown.
Post by l***@public.gmane.org
= applyAsTemplate indexCtx
3. Pandoc can now render the markdown. Fortunately pandoc can deal
with interleaved HTML, *BUT* this interleaved HTML should not be
indented: otherwise it will look as <code> to pandoc. I solved this
problem by reformatting `templates/post-list.html`.
Post by l***@public.gmane.org
= return . renderPandoc
4. Now or entire string is in HTML format. We can safely pass it to
other templates.
Post by l***@public.gmane.org
= loadAndApplyTemplate "templates/default.html" indexCtx
5. `relativizeUrls` takes an HTML string and, well, relativizes URLs.
Post by l***@public.gmane.org
= relativizeUrls
I hope this makes it clear. I'm attaching a patch so you can see the
different formatting in `templates/post-list.html`. Do mail our list
again if something is not clear!

Hope this helps,
Peace,
Jasper
Post by l***@public.gmane.org
Greetings.
I am a Haskell noob playing around with hakyll.
I took the default site produced by hakyll-init and converted the index.html
to a index.markdown file. Not for any good reason, just to play around.
Here's the result: https://github.com/duk3luk3/hakylltestsite
match "index.markdown" $ do
route $ setExtension "html"
compile $ do
posts <- recentFirst =<< loadAll "posts/*"
let indexCtx =
listField "posts" postCtx (return posts) `mappend`
constField "title" "Home" `mappend`
defaultContext
getResourceBody
= applyAsTemplate indexCtx
= loadAndApplyTemplate "templates/default.html" indexCtx
= relativizeUrls
= return . renderPandoc
Nothing else was changed in site.hs.
The result is not pretty. I've tried putting the ">== return . renderPandoc"
in any place, and I've tried using PandocCompiler instead of
getResourceBody. It never gets rendered properly.
What am I missing? How do I make Pandoc play nice with templates?
Best regards
Luke
--
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
For more options, visit https://groups.google.com/groups/opt_out.
--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Luke Erlacher
2013-09-25 10:05:33 UTC
Permalink
Hi!

Ah, I didn't think far enough to realise the indentation was messing me up
here. Many thanks!

Best
Luke
Post by Jasper Van der Jeugt
Hey Luke!
1. Load it as a string of just markdown
getResourceBody
2. Insert the post list. Note that this is an HTML string, which gets
interleaved in the markdown.
Post by l***@public.gmane.org
= applyAsTemplate indexCtx
3. Pandoc can now render the markdown. Fortunately pandoc can deal
with interleaved HTML, *BUT* this interleaved HTML should not be
indented: otherwise it will look as <code> to pandoc. I solved this
problem by reformatting `templates/post-list.html`.
Post by l***@public.gmane.org
= return . renderPandoc
4. Now or entire string is in HTML format. We can safely pass it to
other templates.
Post by l***@public.gmane.org
= loadAndApplyTemplate "templates/default.html" indexCtx
5. `relativizeUrls` takes an HTML string and, well, relativizes URLs.
Post by l***@public.gmane.org
= relativizeUrls
I hope this makes it clear. I'm attaching a patch so you can see the
different formatting in `templates/post-list.html`. Do mail our list
again if something is not clear!
Hope this helps,
Peace,
Jasper
Post by l***@public.gmane.org
Greetings.
I am a Haskell noob playing around with hakyll.
I took the default site produced by hakyll-init and converted the
index.html
Post by l***@public.gmane.org
to a index.markdown file. Not for any good reason, just to play around.
Here's the result: https://github.com/duk3luk3/hakylltestsite
match "index.markdown" $ do
route $ setExtension "html"
compile $ do
posts <- recentFirst =<< loadAll "posts/*"
let indexCtx =
listField "posts" postCtx (return posts) `mappend`
constField "title" "Home" `mappend`
defaultContext
getResourceBody
= applyAsTemplate indexCtx
= loadAndApplyTemplate "templates/default.html"
indexCtx
Post by l***@public.gmane.org
= relativizeUrls
= return . renderPandoc
Nothing else was changed in site.hs.
The result is not pretty. I've tried putting the ">== return .
renderPandoc"
Post by l***@public.gmane.org
in any place, and I've tried using PandocCompiler instead of
getResourceBody. It never gets rendered properly.
What am I missing? How do I make Pandoc play nice with templates?
Best regards
Luke
--
You received this message because you are subscribed to the Google
Groups
Post by l***@public.gmane.org
"hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send
an
Post by l***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Luke Erlacher
2017-05-19 12:11:22 UTC
Permalink
Hi,

I'm now changing up my site and this isn't working (anymore?).

I have this code:

match "index.de.html" $ do
route idRoute
compile $ do
posts <- recentFirst =<< loadAll "posts/**.de.md"
--cats <- buildCategories "posts/**"

let indexCtx = mconcat [
listField "posts" (postCtx tags) (return posts),
constField "title" "Home",
constField "lang" "de",
constField "alt_lang" "en",
nameField "name",
defaultContext
]

getResourceBody
= applyAsTemplate indexCtx
= return . renderPandoc
= loadAndApplyTemplate "templates/default.de.html"
indexCtx
= relativizeUrls
• Couldn't match type ‘Compiler (Item String)’ with ‘Item String’
Expected type: Compiler (Item String) -> Compiler (Item String)
Actual type: Item String -> Compiler (Item String)
• In the second argument of ‘(>>=)’, namely
‘loadAndApplyTemplate "templates/default.de.html" indexCtx’
In the first argument of ‘(>>=)’, namely
‘getResourceBody >>= applyAsTemplate indexCtx
= return . renderPandoc
= loadAndApplyTemplate "templates/default.de.html" indexCtx’
getResourceBody >>= applyAsTemplate indexCtx
= return . renderPandoc
= loadAndApplyTemplate "templates/default.de.html" indexCtx
= relativizeUrls
Thanks for looking!
--
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.
Daniel Gnoutcheff
2017-05-19 17:35:08 UTC
Permalink
Post by l***@public.gmane.org
getResourceBody
= applyAsTemplate indexCtx
= return . renderPandoc
= loadAndApplyTemplate "templates/default.de.html" indexCtx
= relativizeUrls
The trouble is with the subexpression that precedes the
"loadAndApplyTemplate" line, namely

getResourceBody >>= applyAsTemplate indexCtx >>= return . renderPandoc

(I've just removed the line breaks for illustrative purposes.)

In order to compile, that subexpression needs to be of type:
Compiler (Item String)
Post by l***@public.gmane.org
GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help
Prelude> import Hakyll
Prelude Hakyll> let indexCtx = mempty :: Context String -- dummy context
Prelude Hakyll> :type getResourceBody >>= applyAsTemplate indexCtx >>= return . renderPandoc
getResourceBody >>= applyAsTemplate indexCtx >>= return . renderPandoc
:: Compiler (Compiler (Item String))
... a compiler that produces another compiler. Not what we want.
Post by l***@public.gmane.org
Prelude Hakyll> :type getResourceBody >>= applyAsTemplate indexCtx >>= renderPandoc
getResourceBody >>= applyAsTemplate indexCtx >>= renderPandoc
:: Compiler (Item String)
HTH!

Later,
Daniel

P.S. this is actually more of a Haskell question than a Hakyll question.
If you have more problems with compiler errors, you may want to try a
Haskell help forum.
--
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.
Loading...