{-# LANGUAGE QuasiQuotes #-}

module Drasil.Generator.Website
  ( exportWebsite,
  )
where

import Control.Lens ((^.))
import Drasil.Build.Artifacts (directory, file, localPath, ps, writeFiles)
import Drasil.Generator.Formats (Filename)
import Drasil.System (DrasilWebsite, systemdb, webRefs)
import Language.Drasil (Document, Stage (Equational))
import Language.Drasil.Printers (Notation (Engineering), genHTML, makeCSS, piSys)
import Language.Drasil.Printing.Import (makeDocument)

-- | Generate a "website" (an HTML file with a CSS stylesheet) softifact.
exportWebsite :: DrasilWebsite -> Document -> Filename -> IO ()
exportWebsite :: DrasilWebsite -> Document -> Filename -> IO ()
exportWebsite DrasilWebsite
syst Document
doc Filename
fileName = do
  let printSetting :: PrintingInformation
printSetting = ChunkDB
-> Map UID Reference
-> Stage
-> Notation
-> [LabelledContent]
-> PrintingInformation
piSys (DrasilWebsite
syst DrasilWebsite -> Getting ChunkDB DrasilWebsite ChunkDB -> ChunkDB
forall s a. s -> Getting a s a -> a
^. Getting ChunkDB DrasilWebsite ChunkDB
forall c. HasSystemMeta c => Lens' c ChunkDB
Lens' DrasilWebsite ChunkDB
systemdb) (DrasilWebsite
syst DrasilWebsite
-> Getting (Map UID Reference) DrasilWebsite (Map UID Reference)
-> Map UID Reference
forall s a. s -> Getting a s a -> a
^. Getting (Map UID Reference) DrasilWebsite (Map UID Reference)
Lens' DrasilWebsite (Map UID Reference)
webRefs) Stage
Equational Notation
Engineering []
      pd :: Document
pd = PrintingInformation -> Document -> Document
makeDocument PrintingInformation
printSetting Document
doc
      website :: FileLayout Doc
website =
        PathSegment -> [FileLayout Doc] -> FileLayout Doc
forall (f :: * -> *) doc.
Foldable f =>
PathSegment -> f (FileLayout doc) -> FileLayout doc
directory
          [ps|Website|]
          [ PathSegment -> [FileLayout Doc] -> FileLayout Doc
forall (f :: * -> *) doc.
Foldable f =>
PathSegment -> f (FileLayout doc) -> FileLayout doc
directory
              [ps|HTML|]
              [ PathSegment -> Doc -> FileLayout Doc
forall doc. PathSegment -> doc -> FileLayout doc
file [ps|{fileName}.html|] (Doc -> FileLayout Doc) -> Doc -> FileLayout Doc
forall a b. (a -> b) -> a -> b
$ Filename -> Document -> Doc
genHTML Filename
fileName Document
pd,
                PathSegment -> Doc -> FileLayout Doc
forall doc. PathSegment -> doc -> FileLayout doc
file [ps|{fileName}.css|] (Doc -> FileLayout Doc) -> Doc -> FileLayout Doc
forall a b. (a -> b) -> a -> b
$ Document -> Doc
makeCSS Document
doc
              ]
          ]

  OsPath -> FileLayout Doc -> IO ()
forall doc. Renderable doc => OsPath -> FileLayout doc -> IO ()
writeFiles OsPath
localPath FileLayout Doc
website