Documentation
It’s a ClickHaskell documentation compiler code
which is powered by Hakyll static compiler
You can start live server on http://127.0.0.1:8000 via cabal
cabal run documentation-compiler -- watch
or build static site via cabal or nix wrapper
cabal run documentation-compiler -- build
nix build .#documentation
Compiler
{-# LANGUAGE OverloadedStrings #-}
module DocumentationCompiler where
import GHC.IO.Encoding as Encoding (setLocaleEncoding, utf8)
import System.FilePath
</>), normalise, dropFileName, dropExtension
( (
, replaceExtension, takeBaseName, replaceFileName
)import Hakyll
main :: IO ()
= do
main
Encoding.setLocaleEncoding Encoding.utf8
="."} $ do
hakyllWith defaultConfiguration{providerDirectory
-- html templates
"contribution/template.html" $ compile templateCompiler
match
let -- documentation content
pattern = ("**.lhs" .||. "**.md") .&&. (complement "ChangeLog.md")
-- tranforms file paths to actual links
=
filePathToUrlPath filePath case takeBaseName filePath of
"README" -> replaceFileName filePath "index.html"
-> replaceExtension filePath "html"
_
-- beautifies urls for navigation bar
beautifyUrl path| takeBaseName path == "index" = normalise ("/" </> dropFileName path)
| otherwise = normalise ("/" </> path)
-- documentation references compilation
pattern $ do
match $ filePathToUrlPath . toFilePath)
route (customRoute $ do
compile -- load all used file paths to pass it into <nav>
<-
navigation traverse (makeItem . beautifyUrl . filePathToUrlPath . toFilePath)
=<< getMatches pattern
-- compile every file
pandocCompiler>>=
loadAndApplyTemplate"contribution/template.html"
<> mkNavigationCtx navigation)
(defaultContext >>= relativizeUrls
mkNavigationCtx :: [Item FilePath] -> Context String
=
mkNavigationCtx navigation
listField"nav"
mconcat
("link" (pure . itemBody)
[ field "linkName" (pure . dropExtension . itemBody)
, field
]
)pure navigation) (