Generate all recipes index.html

TODO: Include date
This commit is contained in:
Niels G. W. Serup 2024-10-14 23:59:29 +02:00
parent 0e98373389
commit e51e7a5376
No known key found for this signature in database
GPG Key ID: 38EEEBCE67324F19
1 changed files with 11 additions and 6 deletions

View File

@ -1,6 +1,6 @@
module SiteGenerator (generateSite) where
import Types (Token)
import Types (Token(..))
import DependencyGenerator
import Functions
@ -8,7 +8,7 @@ import Data.Text (Text)
import qualified Data.Text as T
import Control.Monad (forM_)
handleRecipeDir :: Token FilePath -> Token Template -> Token FilePath -> Token FilePath -> DepGenM (Token Text)
handleRecipeDir :: Token FilePath -> Token Template -> Token FilePath -> Token FilePath -> DepGenM (Token (Text, FilePath))
handleRecipeDir outputDir htmlTemplate indexName dir = do
recipeDirOut <- joinPaths outputDir dir
makeDir recipeDirOut
@ -42,7 +42,7 @@ handleRecipeDir outputDir htmlTemplate indexName dir = do
html <- applyTemplate htmlTemplate
$ writeHtml pandoc
saveTextFile html (joinPaths recipeDirOut indexName)
pure title
pure $ TupleToken title dir
handleFontDir :: Token FilePath -> Token FilePath -> DepGenM ()
handleFontDir outputDir dir = do
@ -61,12 +61,17 @@ generateSite = do
-- Handle recipes
recipesDir <- inject "retter"
makeDir $ joinPaths outputDir recipesDir
outputRecipesDir <- joinPaths outputDir recipesDir
makeDir $ outputRecipesDir
recipeSubDirs <- filterDepGenM isDirectory
$ mapDepGenM (joinPaths recipesDir)
$ listDirectory recipesDir
_titles <- mapDepGenM (handleRecipeDir outputDir htmlTemplate indexName) recipeSubDirs
-- TODO: Use titles
infos <- mapDepGenM (handleRecipeDir outputDir htmlTemplate indexName) recipeSubDirs
allRecipesHtml <- applyTemplate htmlTemplate
$ writeHtml
$ readMarkdown
$ onToken (T.append "# Alle retter\n\n" . T.intercalate "\n" . map (\(t, u) -> T.concat ["- ", "[", t, "](/", T.pack u, ")"])) infos
saveTextFile allRecipesHtml (joinPaths outputRecipesDir indexName)
-- Handle about page
outputAboutDir <- joinPaths outputDir (inject "om")