Generate an epub version for each post

189 views
Skip to first unread message

ma...@louisroche.net

unread,
Jul 7, 2013, 9:44:18 AM7/7/13
to hak...@googlegroups.com
Hi,

I'm trying to compile an epub version of every posts in addition to the html one. I know that pandoc can generate an epub, so it should be possible

I looked at the tutorial to have a different version of a post, but it only says how to distinguish the two versions. But it also talks about `pandocCompilerWith'. It may be the function that I should use, but I don't understand how. I think that I should do something with defaultHakyllWriterOptions and the WriterOptions type to specify the output format. Haskell is not my main language. 

Could you give me examples to do that? Or maybe examples to generate an pdf version. I can try to adapt it after.

Thanks

Louis

Jasper Van der Jeugt

unread,
Jul 15, 2013, 10:11:15 AM7/15/13
to hakyll
Hello,

I have been travelling a lot for the past few days and will continue
to do so for another week or two. My apologies for the late reply.

In order to do this, you want to use `readPandoc` [1]. This converts
the markdown to the internal format used by Pandoc. You can then use
the Pandoc API [2] to convert this to the EPUB format.

I think the result would look like e.g.,:

compile $ do
body <- getResourceBody
withItemBody
(\p -> unsafeCompiler $ writeEPUB defaultHakyllWriterOptions p)
(readPandoc body)

[1]: http://jaspervdj.be/hakyll/reference/Hakyll-Web-Pandoc.html#v:readPandoc
[2]: http://hackage.haskell.org/packages/archive/pandoc/1.11.1/doc/html/Text-Pandoc.html#v:writeEPUB

Hope this helps,
Peace,
Jasper
> --
> 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+un...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

ma...@louisroche.net

unread,
Jul 29, 2013, 5:11:26 PM7/29/13
to hak...@googlegroups.com
Hi,

Thanks for your answer. I was very busy, I'm sorry for not responding faster.

I tried your solution and it compiles. Big improvement. But the epub file contains no text. It's a valid epub file, but without the text of my post.

The sources are in http://paste.isomorphis.me/EOb
It's almost the default site.hs

Louis

Jasper Van der Jeugt

unread,
Aug 12, 2013, 6:52:30 PM8/12/13
to hakyll
Hey Louis,

I tried your code and encountered the same problem: I'm not sure how
`writeEPUB` works. Did you figure this out in the meanwhile? I can
invest some time to solve this issue later.

Peace,
Jasper

ma...@louisroche.net

unread,
Aug 19, 2013, 7:40:43 PM8/19/13
to hak...@googlegroups.com
Hi,

writeEPUB needs a template to generate the epub. If the writerTemplate in the writerOptions is empty, the epub will be empty.

With this code, I have the content of the blog post in the epub. I just need to add the post title and the author name.
The read of the template at the beginning of the main seems to be ugly, but I failed to put it somewhere else.

If I want to add a link to the epub file in the html version, should I do it in the templates/post.html template?

Thanks again for your help

Louis
Reply all
Reply to author
Forward
0 new messages