From e51e7a5376b6641c0e18f30598a5740fbfffdb63 Mon Sep 17 00:00:00 2001 From: "Niels G. W. Serup" Date: Mon, 14 Oct 2024 23:59:29 +0200 Subject: [PATCH] Generate all recipes index.html TODO: Include date --- byg/src/SiteGenerator.hs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/byg/src/SiteGenerator.hs b/byg/src/SiteGenerator.hs index 2d6c3f8..ea76679 100644 --- a/byg/src/SiteGenerator.hs +++ b/byg/src/SiteGenerator.hs @@ -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")