personal-1.1.0: Personal web site for Yoo Chung
CopyrightCopyright (C) 2024 Yoo Chung
LicenseAll rights reserved
Maintainerweb@chungyc.org
Safe HaskellSafe-Inferred
LanguageGHC2021

Web.Generate.Contents

Description

Support generation of table of contents in programmatically generated pages on this website. This is for pages where the HTML is directly generated using Haskell code.

For example, the following generates HTML for a table of contents:

>>> import Text.Blaze.Html.Renderer.Pretty (renderHtml)
>>> :{
putStr $ renderHtml$ toc $
  [ Entry "First section" "#first"
    [ Entry "First sub-section" "#first-sub" []
    , Entry "Second sub-section" "#second-sub" []
    ]
  , Entry "Second section" "#second" []
  ]
:}
<nav class="toc">
    <h2>
        Contents
    </h2>
    <ul>
        <li>
            <a href="#first">
                First section
            </a>
            <ul>
                <li>
                    <a href="#first-sub">
                        First sub-section
                    </a>
                </li>
                <li>
                    <a href="#second-sub">
                        Second sub-section
                    </a>
                </li>
            </ul>
        </li>
        <li>
            <a href="#second">
                Second section
            </a>
        </li>
    </ul>
</nav>
Synopsis

Documentation

data Entry Source #

An entry in the table of contents.

Constructors

Entry 

Fields

  • Html

    Title of the section.

  • AttributeValue

    Anchor to the section.

  • [Entry]

    Sub-entries under the section.

toc :: [Entry] -> Html Source #

Generate HTML for the table of contents.