Also build every recipe html page

This commit is contained in:
Niels G. W. Serup 2024-09-25 19:37:49 +02:00
parent daacf2e6fa
commit 4a0ea4d5ef
No known key found for this signature in database
GPG Key ID: 38EEEBCE67324F19
1 changed files with 14 additions and 5 deletions

View File

@ -3,14 +3,23 @@ module SiteGenerator (generateSite) where
import Types
import DependencyGenerator
handleRecipeDir :: Token Template -> Token FilePath -> DepGenM ()
handleRecipeDir _template dir = do
handleRecipeDir :: Token FilePath -> Token Template -> Token FilePath -> DepGenM ()
handleRecipeDir outputDir template dir = do
dirContents <- listDirectory dir
imageFilenames <- filterDepGenM isImageFilename dirContents
convertedImageFilenames <- mapDepGenM convertedImageFilename imageFilenames
flip mapDepGenM_ (ZipToken imageFilenames convertedImageFilenames) $ \files -> do
settings <- inject $ ResizeToWidth 800
convertImage $ TupleToken files settings
recipeFilenameIn <- inject "ret.md"
recipePathIn <- joinPaths $ TupleToken dir recipeFilenameIn
recipeDirOut <- joinPaths $ TupleToken outputDir dir
makeDir recipeDirOut
recipeFilenameOut <- inject "index.html"
recipePathOut <- joinPaths $ TupleToken recipeDirOut recipeFilenameOut
htmlBody <- runPandoc recipePathIn
html <- applyTemplate $ TupleToken template htmlBody
saveFile $ TupleToken html recipePathOut
generateSite :: DepGenM ()
generateSite = do
@ -20,11 +29,11 @@ generateSite = do
template <- readTemplate templateFilename
dir <- inject "retter"
dirContents <- listDirectory dir
mapDepGenM_ (handleRecipeDir template) dirContents
mapDepGenM_ (handleRecipeDir outputDir template) dirContents
aboutPathIn <- inject "om.md"
aboutHtmlBody <- runPandoc aboutPathIn
aboutHtml <- applyTemplate $ TupleToken template aboutHtmlBody
aboutFilenameOut <- inject "om.html"
aboutPathOut <- joinPaths $ TupleToken outputDir aboutFilenameOut
aboutHtmlBody <- runPandoc aboutPathIn
aboutHtml <- applyTemplate $ TupleToken template aboutHtmlBody
saveFile $ TupleToken aboutHtml aboutPathOut