-
Notifications
You must be signed in to change notification settings - Fork 13
/
genhtml.hs
62 lines (54 loc) · 2.17 KB
/
genhtml.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{-# OPTIONS_GHC -fno-warn-tabs #-}
{-# LANGUAGE LambdaCase, ViewPatterns, RecordWildCards, OverloadedStrings #-}
import Document (Draft(..))
import Load14882 (load14882)
import Prelude hiding ((++), (.), writeFile, readFile)
import System.Directory (createDirectoryIfMissing, setCurrentDirectory, getCurrentDirectory, copyFile)
import System.Environment (getArgs)
import Control.Monad (forM_)
import Data.Text.IO (readFile)
import qualified Control.Monad.Parallel as ParallelMonad
import Util hiding (readFile)
import Toc (writeTocFiles)
import Pages (outputDir, PageStyle(..))
import SectionPages
data CmdLineArgs = CmdLineArgs
{ repo :: FilePath
, sectionFileStyle :: PageStyle
, sectionToWrite :: Maybe String }
readCmdLineArgs :: [String] -> CmdLineArgs
readCmdLineArgs = \case
[repo, read -> sectionFileStyle, sec] -> CmdLineArgs{sectionToWrite=Just sec, ..}
[repo, read -> sectionFileStyle] -> CmdLineArgs{sectionToWrite=Nothing,..}
[repo] -> CmdLineArgs{sectionFileStyle=WithExtension,sectionToWrite=Nothing,..}
_ -> error "param: path/to/repo"
main :: IO ()
main = do
cwd <- getCurrentDirectory
CmdLineArgs{..} <- readCmdLineArgs . getArgs
extraMacros <- readFile "macros.tex"
setCurrentDirectory $ repo ++ "/source"
draft@Draft{..} <- load14882 extraMacros
setCurrentDirectory cwd
createDirectoryIfMissing True outputDir
copyFile "icon.png" (outputDir ++ "/icon.png")
forM_ ["expanded.css", "colored.css", "normative-only.css"] $
\f -> do
copyFile f (outputDir ++ "/" ++ f)
case sectionToWrite of
Just abbr -> writeSingleSectionFile sectionFileStyle draft abbr
Nothing -> do
let acts =
[ writeTocFiles sectionFileStyle draft
, writeCssFile
, writeFiguresFile sectionFileStyle draft
, writeFigureFiles sectionFileStyle draft
, writeFootnotesFile sectionFileStyle draft
, writeTablesFile sectionFileStyle draft
, writeTableFiles sectionFileStyle draft
] ++
writeXrefDeltaFiles sectionFileStyle draft ++
writeIndexFiles sectionFileStyle draft index ++
writeSectionFiles sectionFileStyle draft
((), took) <- measure $ ParallelMonad.sequence_ acts
putStrLn $ "Wrote files to " ++ outputDir ++ " in " ++ show (took * 1000) ++ "ms."