Discussion:
table of contents
Qi Qi
2011-07-31 22:01:39 UTC
Permalink
Hi,

I want a table of contents for each of my post. Based on the new
version of Hakyll, I assume it has something to with the
pageRenderPandocWith, and the WriterOptions should be set for it.
Could anyone give an example about it?
Thanks.
Gwern Branwen
2011-07-31 22:05:31 UTC
Permalink
Post by Qi Qi
Hi,
I want a table of contents for each of my post. Based on the new
version of Hakyll, I assume it has something to with the
pageRenderPandocWith, and the WriterOptions should be set for it.
Could anyone give an example about it?
Thanks.
My own site has ToCs. See http://www.gwern.net/hakyll.hs

The ToC option is in a Pandoc option datastructure:

options :: WriterOptions
options = defaultWriterOptions{ writerSectionDivs = True,
writerStandalone = True,
writerTableOfContents = True,
writerTemplate =
"$if(toc)$\n$toc$\n$endif$\n$body$",
writerHTMLMathMethod =
Text.Pandoc.MathML Nothing,
writerEmailObfuscation = NoObfuscation }

Which is then used in a custom compiler

myPageCompiler :: Compiler Resource (Page String)
myPageCompiler = cached "myPageCompiler" $ readPageCompiler >>>
addDefaultFields >>> arr applySelf >>> myPageRenderPandocWith

myPageRenderPandocWith :: Compiler (Page String) (Page String)
myPageRenderPandocWith = pageReadPandocWith defaultHakyllParserState
Post by Qi Qi
^ fmap pandocTransform >>^ fmap (writePandocWith options)
And then in `main`, we bring it all together:

group "html" $ match "**.page" $ do
route $ setExtension ""
compile $ myPageCompiler
Post by Qi Qi
requireA "templates/sidebar.markdown" (setFieldA
"sidebar" $ arr pageBody)
Post by Qi Qi
applyTemplateCompiler "templates/default.html"
--
gwern
http://www.gwern.net
Qi Qi
2011-07-31 22:11:34 UTC
Permalink
I got some ideas from your example, Gwern. Thank you!
Thanks for your quick response!
Post by Qi Qi
Hi,
I want a table of contents for each of my post. Based on the new
version of Hakyll, I assume it has something to with the
pageRenderPandocWith, and the WriterOptions should be set for it.
Could anyone give an example about it?
Thanks.
My own site has ToCs. Seehttp://www.gwern.net/hakyll.hs
options :: WriterOptions
options = defaultWriterOptions{ writerSectionDivs = True,
                                       writerStandalone = True,
                                       writerTableOfContents = True,
                                       writerTemplate =
"$if(toc)$\n$toc$\n$endif$\n$body$",
                                       writerHTMLMathMethod =
Text.Pandoc.MathML Nothing,
                                       writerEmailObfuscation = NoObfuscation }
Which is then used in a custom compiler
myPageCompiler :: Compiler Resource (Page String)
myPageCompiler = cached "myPageCompiler" $ readPageCompiler >>>
addDefaultFields >>> arr applySelf >>> myPageRenderPandocWith
myPageRenderPandocWith :: Compiler (Page String) (Page String)
myPageRenderPandocWith = pageReadPandocWith defaultHakyllParserState
Post by Qi Qi
^ fmap pandocTransform >>^ fmap (writePandocWith options)
          group "html" $ match "**.page" $ do
               route $ setExtension ""
               compile $ myPageCompiler
                 >>> requireA "templates/sidebar.markdown" (setFieldA
"sidebar" $ arr pageBody)
                 >>> applyTemplateCompiler "templates/default.html"
--
gwernhttp://www.gwern.net
Vladimír Čunát
2012-02-21 17:28:35 UTC
Permalink
Post by Gwern Branwen
My own site has ToCs. See http://www.gwern.net/hakyll.hs
Hello,
could you advise me about the TOCs? I thought Pandoc should generate
them and place them in the toc attribute but it does not for me (setting
the option just converts headings into links).

Thanks
Vlada
Gwern Branwen
2012-02-21 17:45:46 UTC
Permalink
could you advise me about the TOCs? I thought Pandoc should generate them
and place them in the toc attribute but it does not for me (setting the
option just converts headings into links).
Could you be more specific?
--
gwern
http://www.gwern.net
Jasper Van der Jeugt
2012-02-21 17:54:44 UTC
Permalink
Pandoc needs a few options to generate a TOC. I'm writing this from my
mobile so I can't really elaborate, but I use TOCs on the Hakyll website of
which you can find the source here [1].

[1]: https://github.com/jaspervdj/hakyll/tree/master/web

Hope this helps,
Cheers,
Jasper
Post by Gwern Branwen
could you advise me about the TOCs? I thought Pandoc should generate them
and place them in the toc attribute but it does not for me (setting the
option just converts headings into links).
Could you be more specific?
--
gwern
http://www.gwern.net
Vladimír Čunát
2012-02-22 10:38:46 UTC
Permalink
Post by Jasper Van der Jeugt
Pandoc needs a few options to generate a TOC. I'm writing this from my
mobile so I can't really elaborate, but I use TOCs on the Hakyll website
of which you can find the source here [1].
Thanks, Jasper.
I found the whole problem was just missing writerStandalone = True. It
seems strange to me but it works now.

By the way, I seem to be the first to flattr Hakyll, which is no wonder
when you don't have the button anywhere (glimpsed in the template).

Vlada
Jasper Van der Jeugt
2012-02-22 22:58:43 UTC
Permalink
Haha, yes, I was unsure if I should add a flattr button to the site,
so I put it in comments. I've made it visible now :-)

Cheers,
Jasper
Post by Vladimír Čunát
Post by Jasper Van der Jeugt
Pandoc needs a few options to generate a TOC. I'm writing this from my
mobile so I can't really elaborate, but I use TOCs on the Hakyll website
of which you can find the source here [1].
Thanks, Jasper.
I found the whole problem was just missing writerStandalone = True. It seems
strange to me but it works now.
By the way, I seem to be the first to flattr Hakyll, which is no wonder when
you don't have the button anywhere (glimpsed in the template).
Vlada
k***@public.gmane.org
2014-02-05 11:23:53 UTC
Permalink
It would be nice, if 'table of contents' could be specified in the meta tag
eg

----
title: Funky Friday
toc: yes
----
Post by Qi Qi
Hi,
I want a table of contents for each of my post. Based on the new
version of Hakyll, I assume it has something to with the
pageRenderPandocWith, and the WriterOptions should be set for it.
Could anyone give an example about it?
Thanks.
--
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
2014-02-05 13:26:22 UTC
Permalink
Hmm, that shouldn't be too hard using something like:

identifier <- getUnderlying
toc <- getMetadataField identifier "toc"
case toc of
Just "yes" -> -- do something
_ -> -- do something else

Hope this helps,
Peace,
Jasper
Post by k***@public.gmane.org
It would be nice, if 'table of contents' could be specified in the meta
tag eg
----
title: Funky Friday
toc: yes
----
Post by Qi Qi
Hi,
I want a table of contents for each of my post. Based on the new
version of Hakyll, I assume it has something to with the
pageRenderPandocWith, and the WriterOptions should be set for it.
Could anyone give an example about it?
Thanks.
--
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.
k***@public.gmane.org
2014-02-05 14:48:20 UTC
Permalink
With this I get

Couldn't match type `Compiler' with `Rules'
Expected type: Rules Identifier
Actual type: Compiler Identifier
Post by Jasper Van der Jeugt
identifier <- getUnderlying
toc <- getMetadataField identifier "toc"
case toc of
Just "yes" -> -- do something
_ -> -- do something else
Hope this helps,
Peace,
Jasper
Post by k***@public.gmane.org
It would be nice, if 'table of contents' could be specified in the meta
tag eg
----
title: Funky Friday
toc: yes
----
Post by Qi Qi
Hi,
I want a table of contents for each of my post. Based on the new
version of Hakyll, I assume it has something to with the
pageRenderPandocWith, and the WriterOptions should be set for it.
Could anyone give an example about it?
Thanks.
--
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.
Daniil Frumin
2014-02-05 15:57:55 UTC
Permalink
It should be something like this:

match "what" $ do
route idRoute
compile $ do
ident <- getUnderlying
toc <- getMetadataFeild identifier "toc"
let writerSettings = case toc of
Just "yes" -> myWriterOptionsToc
Nothing -> myWriterOptions
pandocCompilerWith myReaderOptions writerSettings
...

In my config [1] I have the following settings:


myWriterOptions :: WriterOptions
myWriterOptions = defaultHakyllWriterOptions {
writerReferenceLinks = True
, writerHtml5 = True
, writerHighlight = True
}

myWriterOptionsToc :: WriterOptions
myWriterOptionsToc = myWriterOptions {
writerTableOfContents = True
, writerTOCDepth = 2
, writerTemplate = "$if(toc)$<div id=\"toc\">$toc$</div>$endif$\n$body$"
, writerStandalone = True
}

[1] http://hub.darcs.net/co-dan/website/browse/site.hs#207

hope this helps
Post by k***@public.gmane.org
With this I get
Couldn't match type `Compiler' with `Rules'
Expected type: Rules Identifier
Actual type: Compiler Identifier
Post by Jasper Van der Jeugt
identifier <- getUnderlying
toc <- getMetadataField identifier "toc"
case toc of
Just "yes" -> -- do something
_ -> -- do something else
Hope this helps,
Peace,
Jasper
Post by k***@public.gmane.org
It would be nice, if 'table of contents' could be specified in the meta
tag eg
----
title: Funky Friday
toc: yes
----
Post by Qi Qi
Hi,
I want a table of contents for each of my post. Based on the new
version of Hakyll, I assume it has something to with the
pageRenderPandocWith, and the WriterOptions should be set for it.
Could anyone give an example about it?
Thanks.
--
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
For more options, visit https://groups.google.com/groups/opt_out.
--
Sincerely yours,
-- Daniil
--
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.
k***@public.gmane.org
2014-02-06 05:46:03 UTC
Permalink
Thanks a lot; this works great.
Michel
Post by Daniil Frumin
match "what" $ do
route idRoute
compile $ do
ident <- getUnderlying
toc <- getMetadataFeild identifier "toc"
let writerSettings = case toc of
Just "yes" -> myWriterOptionsToc
Nothing -> myWriterOptions
pandocCompilerWith myReaderOptions writerSettings
...
myWriterOptions :: WriterOptions
myWriterOptions = defaultHakyllWriterOptions {
writerReferenceLinks = True
, writerHtml5 = True
, writerHighlight = True
}
myWriterOptionsToc :: WriterOptions
myWriterOptionsToc = myWriterOptions {
writerTableOfContents = True
, writerTOCDepth = 2
, writerTemplate = "$if(toc)$<div
id=\"toc\">$toc$</div>$endif$\n$body$"
, writerStandalone = True
}
[1] http://hub.darcs.net/co-dan/website/browse/site.hs#207
hope this helps
Post by k***@public.gmane.org
With this I get
Couldn't match type `Compiler' with `Rules'
Expected type: Rules Identifier
Actual type: Compiler Identifier
Post by Jasper Van der Jeugt
identifier <- getUnderlying
toc <- getMetadataField identifier "toc"
case toc of
Just "yes" -> -- do something
_ -> -- do something else
Hope this helps,
Peace,
Jasper
Post by k***@public.gmane.org
It would be nice, if 'table of contents' could be specified in the
meta
Post by k***@public.gmane.org
Post by Jasper Van der Jeugt
Post by k***@public.gmane.org
tag eg
----
title: Funky Friday
toc: yes
----
Post by Qi Qi
Hi,
I want a table of contents for each of my post. Based on the new
version of Hakyll, I assume it has something to with the
pageRenderPandocWith, and the WriterOptions should be set for it.
Could anyone give an example about it?
Thanks.
--
You received this message because you are subscribed to the Google
Groups
Post by k***@public.gmane.org
Post by Jasper Van der Jeugt
Post by k***@public.gmane.org
"hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send
an
Post by k***@public.gmane.org
Post by Jasper Van der Jeugt
Post by k***@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
Post by k***@public.gmane.org
"hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send
an
Post by k***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
--
Sincerely yours,
-- Daniil
--
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.
j***@gmail.com
2018-01-07 06:39:57 UTC
Permalink
Is there anyway to get ToC in a context field, rather than using
writerTemplate? With say a template/*.html file like

<div>$body$</div>
<div>$toc$</div>

With this I can place ToC in different places for different pages.

Thanks,
Post by k***@public.gmane.org
Thanks a lot; this works great.
Michel
Post by Daniil Frumin
match "what" $ do
route idRoute
compile $ do
ident <- getUnderlying
toc <- getMetadataFeild identifier "toc"
let writerSettings = case toc of
Just "yes" -> myWriterOptionsToc
Nothing -> myWriterOptions
pandocCompilerWith myReaderOptions writerSettings
...
myWriterOptions :: WriterOptions
myWriterOptions = defaultHakyllWriterOptions {
writerReferenceLinks = True
, writerHtml5 = True
, writerHighlight = True
}
myWriterOptionsToc :: WriterOptions
myWriterOptionsToc = myWriterOptions {
writerTableOfContents = True
, writerTOCDepth = 2
, writerTemplate = "$if(toc)$<div
id=\"toc\">$toc$</div>$endif$\n$body$"
, writerStandalone = True
}
[1] http://hub.darcs.net/co-dan/website/browse/site.hs#207
hope this helps
Post by k***@public.gmane.org
With this I get
Couldn't match type `Compiler' with `Rules'
Expected type: Rules Identifier
Actual type: Compiler Identifier
Post by Jasper Van der Jeugt
identifier <- getUnderlying
toc <- getMetadataField identifier "toc"
case toc of
Just "yes" -> -- do something
_ -> -- do something else
Hope this helps,
Peace,
Jasper
Post by k***@public.gmane.org
It would be nice, if 'table of contents' could be specified in the
meta
Post by k***@public.gmane.org
Post by Jasper Van der Jeugt
Post by k***@public.gmane.org
tag eg
----
title: Funky Friday
toc: yes
----
Post by Qi Qi
Hi,
I want a table of contents for each of my post. Based on the new
version of Hakyll, I assume it has something to with the
pageRenderPandocWith, and the WriterOptions should be set for it.
Could anyone give an example about it?
Thanks.
--
You received this message because you are subscribed to the Google
Groups
Post by k***@public.gmane.org
Post by Jasper Van der Jeugt
Post by k***@public.gmane.org
"hakyll" group.
To unsubscribe from this group and stop receiving emails from it,
send an
Post by k***@public.gmane.org
Post by Jasper Van der Jeugt
Post by k***@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
Post by k***@public.gmane.org
"hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send
an
Post by k***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
--
Sincerely yours,
-- Daniil
--
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.
Jasper Van der Jeugt
2018-01-07 11:34:38 UTC
Permalink
Hey Jerin,

It's a bit hacky, but you can render the content a second time and use
a writer template that _only_ picks out the ToC.

Jasper
Post by j***@gmail.com
Is there anyway to get ToC in a context field, rather than using
writerTemplate? With say a template/*.html file like
<div>$body$</div>
<div>$toc$</div>
With this I can place ToC in different places for different pages.
Thanks,
Post by k***@public.gmane.org
Thanks a lot; this works great.
Michel
Post by Daniil Frumin
match "what" $ do
route idRoute
compile $ do
ident <- getUnderlying
toc <- getMetadataFeild identifier "toc"
let writerSettings = case toc of
Just "yes" -> myWriterOptionsToc
Nothing -> myWriterOptions
pandocCompilerWith myReaderOptions writerSettings
...
myWriterOptions :: WriterOptions
myWriterOptions = defaultHakyllWriterOptions {
writerReferenceLinks = True
, writerHtml5 = True
, writerHighlight = True
}
myWriterOptionsToc :: WriterOptions
myWriterOptionsToc = myWriterOptions {
writerTableOfContents = True
, writerTOCDepth = 2
, writerTemplate = "$if(toc)$<div
id=\"toc\">$toc$</div>$endif$\n$body$"
, writerStandalone = True
}
[1] http://hub.darcs.net/co-dan/website/browse/site.hs#207
hope this helps
Post by k***@public.gmane.org
With this I get
Couldn't match type `Compiler' with `Rules'
Expected type: Rules Identifier
Actual type: Compiler Identifier
Post by Jasper Van der Jeugt
identifier <- getUnderlying
toc <- getMetadataField identifier "toc"
case toc of
Just "yes" -> -- do something
_ -> -- do something else
Hope this helps,
Peace,
Jasper
Post by k***@public.gmane.org
It would be nice, if 'table of contents' could be specified in the meta
tag eg
----
title: Funky Friday
toc: yes
----
Post by Qi Qi
Hi,
I want a table of contents for each of my post. Based on the new
version of Hakyll, I assume it has something to with the
pageRenderPandocWith, and the WriterOptions should be set for it.
Could anyone give an example about it?
Thanks.
--
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
For more options, visit https://groups.google.com/groups/opt_out.
--
Sincerely yours,
-- Daniil
--
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/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.
Jerin Philip
2018-01-07 12:54:31 UTC
Permalink
What would be the non-hacky way to do this?
Post by Jasper Van der Jeugt
Hey Jerin,
It's a bit hacky, but you can render the content a second time and use
a writer template that _only_ picks out the ToC.
Jasper
Post by j***@gmail.com
Is there anyway to get ToC in a context field, rather than using
writerTemplate? With say a template/*.html file like
<div>$body$</div>
<div>$toc$</div>
With this I can place ToC in different places for different pages.
Thanks,
Post by k***@public.gmane.org
Thanks a lot; this works great.
Michel
Post by Daniil Frumin
match "what" $ do
route idRoute
compile $ do
ident <- getUnderlying
toc <- getMetadataFeild identifier "toc"
let writerSettings = case toc of
Just "yes" -> myWriterOptionsToc
Nothing -> myWriterOptions
pandocCompilerWith myReaderOptions writerSettings
...
myWriterOptions :: WriterOptions
myWriterOptions = defaultHakyllWriterOptions {
writerReferenceLinks = True
, writerHtml5 = True
, writerHighlight = True
}
myWriterOptionsToc :: WriterOptions
myWriterOptionsToc = myWriterOptions {
writerTableOfContents = True
, writerTOCDepth = 2
, writerTemplate = "$if(toc)$<div
id=\"toc\">$toc$</div>$endif$\n$body$"
, writerStandalone = True
}
[1] http://hub.darcs.net/co-dan/website/browse/site.hs#207
hope this helps
Post by k***@public.gmane.org
With this I get
Couldn't match type `Compiler' with `Rules'
Expected type: Rules Identifier
Actual type: Compiler Identifier
Post by Jasper Van der Jeugt
identifier <- getUnderlying
toc <- getMetadataField identifier "toc"
case toc of
Just "yes" -> -- do something
_ -> -- do something else
Hope this helps,
Peace,
Jasper
Post by k***@public.gmane.org
It would be nice, if 'table of contents' could be specified in the meta
tag eg
----
title: Funky Friday
toc: yes
----
Post by Qi Qi
Hi,
I want a table of contents for each of my post. Based on the new
version of Hakyll, I assume it has something to with the
pageRenderPandocWith, and the WriterOptions should be set for it.
Could anyone give an example about it?
Thanks.
--
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
Post by j***@gmail.com
Post by k***@public.gmane.org
Post by Daniil Frumin
Post by k***@public.gmane.org
an
For more options, visit https://groups.google.com/groups/opt_out.
--
Sincerely yours,
-- Daniil
--
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/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
For more options, visit https://groups.google.com/d/optout.
--
Jerin Philip
--
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...