2024-09-23 22:11:54 +02:00
|
|
|
module SiteGenerator (generateSite) where
|
|
|
|
|
2024-10-05 17:35:47 +02:00
|
|
|
import Prelude hiding (String, FilePath)
|
|
|
|
|
2024-09-23 22:11:54 +02:00
|
|
|
import Types
|
|
|
|
import DependencyGenerator
|
|
|
|
|
2024-10-05 15:58:55 +02:00
|
|
|
import Control.Monad (forM_)
|
2024-10-05 17:35:47 +02:00
|
|
|
|
2024-10-05 20:35:34 +02:00
|
|
|
handleRecipeDir :: Token FilePath -> Token Template -> Token FilePath -> Token FilePath -> DepGenM ()
|
2024-10-05 22:51:13 +02:00
|
|
|
handleRecipeDir outputDir htmlTemplate indexName dir = do
|
2024-10-05 20:35:34 +02:00
|
|
|
recipeDirOut <- joinPaths outputDir dir
|
2024-09-26 00:09:48 +02:00
|
|
|
makeDir recipeDirOut
|
2024-10-05 22:51:13 +02:00
|
|
|
imageFilenames <- filterDepGenM (hasExtension (inject ["jpg"]))
|
|
|
|
$ listDirectory dir
|
|
|
|
htmlBodyImages <- forDepGenM imageFilenames $ \name -> do
|
|
|
|
path <- joinPaths dir name
|
|
|
|
path `copyTo` outputDir
|
|
|
|
(base, ext) <- untupleDepGenM $ fileComponents name
|
|
|
|
thumbnailName <- concatStrings [ pure base, inject "-thumbnail.", pure ext ]
|
|
|
|
convertImage path (joinPaths recipeDirOut thumbnailName) (inject (ResizeToWidth 800))
|
|
|
|
concatTexts [ inject "<p class=\"image\"><a href=\""
|
|
|
|
, toText name
|
|
|
|
, inject "\"><img src=\""
|
|
|
|
, toText thumbnailName
|
|
|
|
, inject "\"></a></p>\n"
|
|
|
|
]
|
2024-10-05 19:15:20 +02:00
|
|
|
ingredienserHeadline <- inject "## Ingredienser"
|
2024-10-05 22:51:13 +02:00
|
|
|
mdTemplate <- makeTemplate
|
|
|
|
(readTextFile (joinPaths dir (inject "ret.md")))
|
|
|
|
ingredienserHeadline
|
|
|
|
html <- applyTemplate htmlTemplate
|
|
|
|
$ runPandoc
|
|
|
|
$ applyTemplate mdTemplate
|
|
|
|
$ concatTexts [ inject "<p class=\"imagetext\">Opskrift fortsætter efter billedet.</p>\n"
|
|
|
|
, concatTexts htmlBodyImages
|
|
|
|
, inject "\n"
|
|
|
|
, pure ingredienserHeadline
|
|
|
|
]
|
|
|
|
saveTextFile html (joinPaths recipeDirOut indexName)
|
|
|
|
|
|
|
|
handleFontDir :: Token FilePath -> Token FilePath -> DepGenM ()
|
|
|
|
handleFontDir outputDir dir = do
|
|
|
|
makeDir $ joinPaths outputDir dir
|
|
|
|
paths <- filterDepGenM (hasExtension (inject ["woff2", "css"]))
|
|
|
|
$ mapDepGenM (joinPaths dir)
|
|
|
|
$ listDirectory dir
|
|
|
|
mapDepGenM_ (`copyTo` outputDir) paths
|
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-10-05 22:51:13 +02:00
|
|
|
htmlTemplate <- makeTemplate (readTextFile (inject "template.html")) (inject "CONTENT")
|
|
|
|
indexName <- inject "index.html"
|
|
|
|
|
|
|
|
-- Handle recipes
|
2024-09-25 23:51:33 +02:00
|
|
|
recipesDir <- inject "retter"
|
2024-10-05 20:35:34 +02:00
|
|
|
makeDir $ joinPaths outputDir recipesDir
|
2024-10-05 22:51:13 +02:00
|
|
|
recipeSubDirs <- filterDepGenM isDirectory
|
|
|
|
$ mapDepGenM (joinPaths recipesDir)
|
|
|
|
$ listDirectory recipesDir
|
|
|
|
mapDepGenM_ (handleRecipeDir outputDir htmlTemplate indexName) recipeSubDirs
|
2024-10-05 17:35:47 +02:00
|
|
|
|
2024-10-05 22:51:13 +02:00
|
|
|
-- Handle about page
|
|
|
|
outputAboutDir <- joinPaths outputDir (inject "om")
|
|
|
|
makeDir outputAboutDir
|
|
|
|
aboutHtml <- applyTemplate htmlTemplate $ runPandoc $ readTextFile $ inject "om.md"
|
|
|
|
saveTextFile aboutHtml (joinPaths outputAboutDir indexName)
|
|
|
|
|
|
|
|
-- Handle style
|
|
|
|
inject "style.css" `copyTo` outputDir
|
|
|
|
|
|
|
|
-- Handle images
|
|
|
|
imgDir <- inject "img"
|
|
|
|
makeDir $ joinPaths outputDir imgDir
|
|
|
|
forM_ ["mad-icon.png", "mad-logo.png"] $ \name ->
|
|
|
|
joinPaths imgDir (inject name) `copyTo` outputDir
|
|
|
|
|
|
|
|
-- Handle fonts
|
|
|
|
fontsDir <- inject "fonts"
|
|
|
|
makeDir $ joinPaths outputDir fontsDir
|
|
|
|
fontSubDirs <- filterDepGenM isDirectory
|
|
|
|
$ mapDepGenM (joinPaths fontsDir)
|
|
|
|
$ listDirectory fontsDir
|
|
|
|
mapDepGenM_ (handleFontDir outputDir) fontSubDirs
|