module SiteGenerator (generateSite) where import Types import DependencyGenerator thumbnailImageFilename :: Token FilePath -> DepGenM' FilePath thumbnailImageFilename filename = do (base, ext) <- untupleDepGenM (fileComponents filename) appendStrings (appendStrings (base, inject "-thumbnail."), ext) 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 thumbnailImageFilenames <- mapDepGenM thumbnailImageFilename imageFilenames mapDepGenM_ (\files -> convertImage (files, inject $ ResizeToWidth 800)) (ZipToken (imageFilenames, thumbnailImageFilenames)) 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"))