Table Of Content in Hakyll
Posted on October 2, 2012
Tags: hacksoft
Hakyll Setup Series
- Setup Mathjax
- Setup PlantUML
- Setup autobuild Hakyll site Git action CI
- Very Simple Hakyll Pandoc Filtering Example
- Add Railroad Syntax to Hakyll
- Table Of Content in Hakyll
- Hakyll Access on LAN server
1 Showcase
---
title: TableOfContent
tags: tech, prog, HakyllSetupSeries
toc: y
---
...content body...
Any value (in our case y
) given to toc
metafield activates the table of content.
2 Setup
--Step 3: Setup WriterOptions
writeMathjaxOptions :: WriterOptions
--writeMathjaxOptions = defaultHakyllWriterOptions
= defaultHakyllWriterOptions
writeMathjaxOptions
{ = True
writerSectionDivs = True
,writerNumberSections = 130
,writerColumns = True
, writerTableOfContents = 3
, writerTOCDepth = MathJax ""
, writerHTMLMathMethod
}
---------------------------------------------------TOC
tocTemplate :: Text.Pandoc.Template Data.Text.Text
=
tocTemplate either error id $ either (error . show) id $
$ runWithDefaultPartials $
runPure "" "<div id=\"TOC\">$toc$</div>\n$body$"
compileTemplate
writeTOCMathjaxOptions :: WriterOptions
= writeMathjaxOptions{
writeTOCMathjaxOptions
= Just tocTemplate
writerTemplate
}
---------------------------------------------------END TOC
--Step 4: Build the compiler using the ReaderOption and Writer Option from Step 2, 3.
mathJaxAddedCompiler :: Compiler (Item String)
= pandocCompilerWithTransform readMathjaxOptions writeTOCMathjaxOptions addToCodeBlock
mathJaxAddedCompiler --Step 5: Replace the line "compile $ pandocCompiler" under "match "posts/*" $ do" with
--"compiler $ mathJaxAddedCompiler"
--exclude Table of Content
mathJaxAddedCompilerExTOC :: Compiler (Item String)
= pandocCompilerWithTransform readMathjaxOptions writeMathjaxOptions addToCodeBlock mathJaxAddedCompilerExTOC
"posts/*" $ do
match $ setExtension "html"
route $ do
compile --Check TOC metadata field filled START
<- getUnderlying
ident <- getMetadataField ident "toc"
toc let chosenCompiler = case toc of
Nothing -> mathJaxAddedCompilerExTOC
Just _ -> mathJaxAddedCompiler
--Check TOC metadata field filled END
chosenCompiler>>= loadAndApplyTemplate "templates/post.html" (postCtxWithTags tags)
>>= saveSnapshot "content"
>>= loadAndApplyTemplate "templates/default.html" (postCtxWithTags tags)
>>= relativizeUrls