ChrisPenner / slick

Static site generator built on Shake configured in Haskell
BSD 3-Clause "New" or "Revised" License
204 stars 24 forks source link

Including a table of contents #12

Closed adamflott closed 4 years ago

adamflott commented 4 years ago

Is there a way to include a table of contents in my posts? I tried altering the WriterOptions and using the pandoc template variables ($table-of-contents$) but those didn't work. Any hints where else to look?

ChrisPenner commented 4 years ago

Hrmm, I'm not sure about this one!

I believe the $table-of-contents$ syntax is part of a pandoc template, so you'll probably have to enable that somehow too? I'm afraid I'm definitely not an expert on pandoc internals 😬 I probably won't be much help on this one, but if you can figure it out I'd love to hear how it goes 😄

srid commented 4 years ago

Seems it is $toc per https://svejcar.dev/posts/2019/11/27/table-of-contents-in-hakyll/

adamflott commented 4 years ago

Thanks @srid that was it!!

How I got it working

myHtml5Options :: Template T.Text -> WriterOptions
myHtml5Options t =
  defaultHtml5Options {
       writerNumberSections  = True
        , writerTableOfContents = True
        , writerTOCDepth        = 20
        , writerTemplate        = Just t
      }

buildPost :: FilePath -> Action (Maybe Post)
buildPost srcPath = cacheAction ("build" :: T.Text, srcPath) $ do
    -- stuff from slick-template

    Right x <- liftIO $ compileTemplate "" "$toc$\n$body$"

    postData    <- markdownToHTMLWithOpts defaultMarkdownOptions (myHtml5Options x) . T.pack $ postContent
ChrisPenner commented 4 years ago

Nice, thanks everyone 👍