2024-09-26 22:48:20 +02:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2024-09-23 22:11:54 +02:00
|
|
|
module SiteGenerator (generateSite) where
|
|
|
|
|
|
|
|
import Types
|
|
|
|
import DependencyGenerator
|
|
|
|
|
2024-09-26 00:33:52 +02:00
|
|
|
thumbnailImageFilename :: Token FilePath -> DepGenM' FilePath
|
|
|
|
thumbnailImageFilename filename = do
|
2024-09-25 23:32:49 +02:00
|
|
|
(base, ext) <- untupleDepGenM (fileComponents filename)
|
2024-09-26 00:33:52 +02:00
|
|
|
appendStrings (appendStrings (base, inject "-thumbnail."), ext)
|
|
|
|
|
|
|
|
makeImageHTML :: Token (FilePath, FilePath) -> DepGenM' String
|
|
|
|
makeImageHTML t = do
|
|
|
|
(thumbnail, actual) <- untupleDepGenM t
|
|
|
|
appendStrings (inject "<p><a href=\"",
|
|
|
|
appendStrings (actual,
|
|
|
|
appendStrings (inject "\"><img src=\"",
|
|
|
|
appendStrings (thumbnail,
|
|
|
|
inject "\"></a></p>"))))
|
2024-09-25 23:32:49 +02:00
|
|
|
|
2024-09-25 23:51:33 +02:00
|
|
|
handleRecipeDir :: Token FilePath -> Token Template -> Token FilePath -> Token FilePath -> DepGenM ()
|
|
|
|
handleRecipeDir outputDir template indexName dir = do
|
2024-09-26 00:09:48 +02:00
|
|
|
recipeDirOut <- joinPaths (outputDir, dir)
|
|
|
|
makeDir recipeDirOut
|
2024-09-23 22:11:54 +02:00
|
|
|
dirContents <- listDirectory dir
|
2024-09-25 23:14:14 +02:00
|
|
|
exts <- unzipSndDepGenM (mapDepGenM fileComponents dirContents)
|
2024-09-25 23:12:32 +02:00
|
|
|
areImageFilenames <- mapDepGenM isImageExtension exts
|
|
|
|
imageFilenames <- filterDepGenM areImageFilenames dirContents
|
2024-09-26 00:02:51 +02:00
|
|
|
imagePaths <- mapDepGenM (curry joinPaths dir) imageFilenames
|
2024-09-26 00:09:48 +02:00
|
|
|
imagePathsOut <- mapDepGenM (curry joinPaths recipeDirOut) imageFilenames
|
2024-09-26 00:06:30 +02:00
|
|
|
mapDepGenM_ copyFile' (ZipToken (imagePaths, imagePathsOut))
|
2024-09-26 00:33:52 +02:00
|
|
|
thumbnailImageFilenames <- mapDepGenM thumbnailImageFilename imageFilenames
|
|
|
|
thumbnailImagePaths <- mapDepGenM (curry joinPaths recipeDirOut) thumbnailImageFilenames
|
2024-09-25 22:09:26 +02:00
|
|
|
mapDepGenM_
|
|
|
|
(\files -> convertImage (files, inject $ ResizeToWidth 800))
|
2024-09-25 23:51:33 +02:00
|
|
|
(ZipToken (imagePaths, thumbnailImagePaths))
|
2024-09-26 00:33:52 +02:00
|
|
|
htmlBodyBase <- runPandoc (joinPaths (dir, inject "ret.md"))
|
|
|
|
htmlBodyImages <- mapDepGenM makeImageHTML (ZipToken (thumbnailImageFilenames, imageFilenames))
|
|
|
|
imagesHtml <- concatStrings htmlBodyImages
|
|
|
|
htmlBody <- appendStrings (htmlBodyBase, imagesHtml)
|
2024-09-25 19:48:45 +02:00
|
|
|
html <- applyTemplate (template, htmlBody)
|
2024-09-25 23:51:33 +02:00
|
|
|
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"
|
|
|
|
outputRecipesDir <- joinPaths (outputDir, recipesDir)
|
|
|
|
makeDir outputRecipesDir
|
2024-09-25 22:09:26 +02:00
|
|
|
template <- readTemplate (inject "template.html")
|
2024-09-25 23:51:33 +02:00
|
|
|
indexName <- inject "index.html"
|
|
|
|
dirContents <- listDirectory recipesDir
|
|
|
|
mapDepGenM_ (handleRecipeDir outputRecipesDir template indexName) dirContents
|
2024-09-25 22:09:26 +02:00
|
|
|
htmlBody <- runPandoc (inject "om.md")
|
|
|
|
html <- applyTemplate (template, htmlBody)
|
2024-09-25 23:51:33 +02:00
|
|
|
aboutDir <- joinPaths (outputDir, inject "om")
|
|
|
|
makeDir aboutDir
|
|
|
|
saveFile (html, joinPaths (aboutDir, indexName))
|