2024-09-23 22:11:54 +02:00
|
|
|
module SiteGenerator (generateSite) where
|
|
|
|
|
|
|
|
import Types
|
|
|
|
import DependencyGenerator
|
|
|
|
|
2024-09-26 23:02:29 +02:00
|
|
|
import Data.Text (Text)
|
|
|
|
|
2024-09-26 00:33:52 +02:00
|
|
|
thumbnailImageFilename :: Token FilePath -> DepGenM' FilePath
|
|
|
|
thumbnailImageFilename filename = do
|
2024-09-26 23:40:26 +02:00
|
|
|
(base, ext) <- untupleDepGenM $ fileComponents filename
|
|
|
|
appendStrings base
|
|
|
|
$ appendStrings (inject "-thumbnail.") ext
|
2024-09-26 00:33:52 +02:00
|
|
|
|
2024-09-26 23:02:29 +02:00
|
|
|
makeImageHTML :: Token (FilePath, FilePath) -> DepGenM' Text
|
2024-09-26 00:33:52 +02:00
|
|
|
makeImageHTML t = do
|
|
|
|
(thumbnail, actual) <- untupleDepGenM t
|
2024-09-26 23:40:26 +02:00
|
|
|
appendTexts
|
|
|
|
(inject "<p><a href=\"")
|
|
|
|
(appendTexts
|
|
|
|
(toText actual)
|
|
|
|
(appendTexts
|
|
|
|
(inject "\"><img src=\"")
|
|
|
|
(appendTexts
|
|
|
|
(toText thumbnail)
|
|
|
|
(inject "\"></a></p>"))))
|
2024-09-25 23:32:49 +02:00
|
|
|
|
2024-09-30 23:31:16 +02:00
|
|
|
handleRecipeDir :: Token FilePath -> Token FilePath -> Token Template -> Token FilePath -> Token FilePath -> DepGenM ()
|
|
|
|
handleRecipeDir inputDir outputDir template indexName name = do
|
|
|
|
dir <- joinPaths inputDir name
|
|
|
|
recipeDirOut <- joinPaths outputDir name
|
2024-09-26 00:09:48 +02:00
|
|
|
makeDir recipeDirOut
|
2024-09-23 22:11:54 +02:00
|
|
|
dirContents <- listDirectory dir
|
2024-09-30 23:31:16 +02:00
|
|
|
areImageFilenames <- mapDepGenM hasImageExtension dirContents
|
2024-09-25 23:12:32 +02:00
|
|
|
imageFilenames <- filterDepGenM areImageFilenames dirContents
|
2024-09-26 23:40:26 +02:00
|
|
|
imagePaths <- mapDepGenM (joinPaths dir) imageFilenames
|
|
|
|
imagePathsOut <- mapDepGenM (joinPaths recipeDirOut) imageFilenames
|
|
|
|
mapDepGenM_ copyFile' $ zipDepGenM imagePaths imagePathsOut
|
2024-09-26 00:33:52 +02:00
|
|
|
thumbnailImageFilenames <- mapDepGenM thumbnailImageFilename imageFilenames
|
2024-09-26 23:40:26 +02:00
|
|
|
thumbnailImagePaths <- mapDepGenM (joinPaths recipeDirOut) thumbnailImageFilenames
|
2024-09-25 22:09:26 +02:00
|
|
|
mapDepGenM_
|
2024-09-26 23:40:26 +02:00
|
|
|
(\files -> convertImage files $ inject $ ResizeToWidth 800)
|
|
|
|
(zipDepGenM imagePaths thumbnailImagePaths)
|
|
|
|
htmlBodyBase <- runPandoc $ joinPaths dir $ inject "ret.md"
|
|
|
|
htmlBodyImages <- mapDepGenM makeImageHTML $ zipDepGenM thumbnailImageFilenames imageFilenames
|
2024-09-26 23:02:29 +02:00
|
|
|
imagesHtml <- concatTexts htmlBodyImages
|
2024-09-26 23:40:26 +02:00
|
|
|
htmlBody <- appendTexts htmlBodyBase imagesHtml
|
|
|
|
html <- applyTemplate template htmlBody
|
|
|
|
saveFile html $ joinPaths recipeDirOut indexName
|
2024-09-23 22:11:54 +02:00
|
|
|
|
2024-09-24 23:09:35 +02:00
|
|
|
generateSite :: DepGenM ()
|
2024-09-23 22:11:54 +02:00
|
|
|
generateSite = do
|
2024-09-24 22:38:52 +02:00
|
|
|
outputDir <- inject "site"
|
|
|
|
makeDir outputDir
|
2024-09-25 23:51:33 +02:00
|
|
|
recipesDir <- inject "retter"
|
2024-09-26 23:40:26 +02:00
|
|
|
outputRecipesDir <- joinPaths outputDir recipesDir
|
2024-09-25 23:51:33 +02:00
|
|
|
makeDir outputRecipesDir
|
2024-09-26 23:40:26 +02:00
|
|
|
template <- readTemplate $ inject "template.html"
|
2024-09-25 23:51:33 +02:00
|
|
|
indexName <- inject "index.html"
|
2024-09-30 23:31:16 +02:00
|
|
|
dirNames <- listDirectory recipesDir
|
|
|
|
dirPaths <- mapDepGenM (joinPaths recipesDir) dirNames
|
|
|
|
dirPathsAreSubdirs <- mapDepGenM isDirectory dirPaths
|
|
|
|
dirNames' <- filterDepGenM dirPathsAreSubdirs dirNames
|
|
|
|
mapDepGenM_ (handleRecipeDir recipesDir outputRecipesDir template indexName) dirNames'
|
2024-09-26 23:40:26 +02:00
|
|
|
html <- applyTemplate template $ runPandoc $ inject "om.md"
|
|
|
|
aboutDir <- joinPaths outputDir $ inject "om"
|
2024-09-25 23:51:33 +02:00
|
|
|
makeDir aboutDir
|
2024-09-26 23:40:26 +02:00
|
|
|
saveFile html $ joinPaths aboutDir indexName
|