module SiteGenerator (generateSite) where import Types import DependencyGenerator handleRecipeDir :: Token FilePath -> Token Template -> Token FilePath -> DepGenM () handleRecipeDir outputDir template dir = do dirContents <- listDirectory dir exts <- unzipSndDepGenM (mapDepGenM fileComponents dirContents) areImageFilenames <- mapDepGenM isImageExtension exts imageFilenames <- filterDepGenM areImageFilenames dirContents convertedImageFilenames <- mapDepGenM convertedImageFilename imageFilenames mapDepGenM_ (\files -> convertImage (files, inject $ ResizeToWidth 800)) (ZipToken (imageFilenames, convertedImageFilenames)) recipeDirOut <- joinPaths (outputDir, dir) makeDir recipeDirOut htmlBody <- runPandoc (joinPaths (dir, inject "ret.md")) html <- applyTemplate (template, htmlBody) saveFile (html, joinPaths (recipeDirOut, inject "index.html")) generateSite :: DepGenM () generateSite = do outputDir <- inject "site" makeDir outputDir template <- readTemplate (inject "template.html") dirContents <- listDirectory (inject "retter") mapDepGenM_ (handleRecipeDir outputDir template) dirContents htmlBody <- runPandoc (inject "om.md") html <- applyTemplate (template, htmlBody) saveFile (html, joinPaths (outputDir, inject "om.html"))