diff --git a/byg/byg.cabal b/byg/byg.cabal index 76b1637..8dcb12a 100644 --- a/byg/byg.cabal +++ b/byg/byg.cabal @@ -26,7 +26,6 @@ library Types.Dependency Types DependencyGenerator - Functions.General Functions.Image Functions.Pandoc Functions.Paths diff --git a/byg/src/Functions.hs b/byg/src/Functions.hs index 94ef3da..c54e724 100644 --- a/byg/src/Functions.hs +++ b/byg/src/Functions.hs @@ -1,13 +1,11 @@ module Functions - ( module Functions.General - , module Functions.Image + ( module Functions.Image , module Functions.Pandoc , module Functions.Paths , module Functions.Template , module Functions.Text ) where -import Functions.General import Functions.Image import Functions.Pandoc import Functions.Paths diff --git a/byg/src/Functions/General.hs b/byg/src/Functions/General.hs deleted file mode 100644 index e7e4053..0000000 --- a/byg/src/Functions/General.hs +++ /dev/null @@ -1,9 +0,0 @@ -module Functions.General - ( elemOf - ) where - -import Types (Token) -import DependencyGenerator (DepGenM, TokenableTo(..), onTupleToken) - -elemOf :: (Eq t, TokenableTo t a, TokenableTo [t] b) => a -> b -> DepGenM (Token Bool) -elemOf = onTupleToken elem diff --git a/byg/src/Functions/Pandoc.hs b/byg/src/Functions/Pandoc.hs index f2bd9bf..34c1d35 100644 --- a/byg/src/Functions/Pandoc.hs +++ b/byg/src/Functions/Pandoc.hs @@ -19,12 +19,11 @@ runPandoc m = case P.runPure m of Right result -> result readMarkdown :: TokenableTo Text a => a -> DepGenM (Token Pandoc) -readMarkdown = onToken $ \contents -> - let settings = P.def { P.readerExtensions = P.extensionsFromList [ P.Ext_raw_html ] } - in runPandoc $ P.readMarkdown settings contents +readMarkdown = onToken $ runPandoc . P.readMarkdown settings + where settings = P.def { P.readerExtensions = P.extensionsFromList [ P.Ext_raw_html ] } writeHtml :: TokenableTo Pandoc a => a -> DepGenM (Token Text) -writeHtml = onToken $ \pandoc -> runPandoc $ P.writeHtml5String P.def pandoc +writeHtml = onToken $ runPandoc . P.writeHtml5String P.def extractTitle :: TokenableTo Pandoc a => a -> DepGenM (Token Text) extractTitle = onToken $ \(PD.Pandoc _ blocks) -> case blocks of diff --git a/byg/src/Functions/Paths.hs b/byg/src/Functions/Paths.hs index 39ea60c..051277a 100644 --- a/byg/src/Functions/Paths.hs +++ b/byg/src/Functions/Paths.hs @@ -9,12 +9,11 @@ module Functions.Paths , copyTo ) where -import Functions.Text (lowerString) -import Functions.General (elemOf) import Types (IsFunctionIO(..), Token(..)) import DependencyGenerator (DepGenM, TokenableTo(..), onToken, onTupleToken, toTupleToken, runFunctionIO, runFunctionIO_, untupleSndDepGenM) +import Data.Char (toLower) import qualified System.Directory as SD joinPaths :: (TokenableTo FilePath a, TokenableTo FilePath b) => a -> b -> DepGenM (Token FilePath) @@ -30,8 +29,8 @@ fileComponents = onToken $ \s -> hasExtension :: (TokenableTo [String] a, TokenableTo FilePath b) => a -> b -> DepGenM (Token Bool) hasExtension exts filename = do - ext <- lowerString =<< untupleSndDepGenM =<< fileComponents filename - ext `elemOf` exts + ext <- onToken (map toLower) =<< untupleSndDepGenM =<< fileComponents filename + onTupleToken elem ext exts data ListDirectory = ListDirectory deriving Show diff --git a/byg/src/Functions/Text.hs b/byg/src/Functions/Text.hs index 5f3dc75..35b8d62 100644 --- a/byg/src/Functions/Text.hs +++ b/byg/src/Functions/Text.hs @@ -1,34 +1,15 @@ module Functions.Text - ( concatStrings - , concatTexts - , lowerString - , toText - , readTextFile + ( readTextFile , saveTextFile ) where import Types (IsFunctionIO(..), Token) -import DependencyGenerator (DepGenM, TokenableTo(..), onToken, toTupleToken, +import DependencyGenerator (DepGenM, TokenableTo(..), toTupleToken, runFunctionIO, runFunctionIO_) -import Data.Char (toLower) import Data.Text (Text) -import qualified Data.Text as T import qualified Data.Text.IO as T -concatStrings :: TokenableTo [String] a => a -> DepGenM (Token String) -concatStrings = onToken concat - -concatTexts :: TokenableTo [Text] a => a -> DepGenM (Token Text) -concatTexts = onToken T.concat - -lowerString :: TokenableTo String a => a -> DepGenM (Token String) -lowerString = onToken (map toLower) - -toText :: TokenableTo String a => a -> DepGenM (Token Text) -toText = onToken T.pack - - data ReadTextFile = ReadTextFile deriving Show instance IsFunctionIO ReadTextFile FilePath Text where evalFunctionIO ReadTextFile s = diff --git a/byg/src/SiteGenerator.hs b/byg/src/SiteGenerator.hs index dec297e..2d6c3f8 100644 --- a/byg/src/SiteGenerator.hs +++ b/byg/src/SiteGenerator.hs @@ -5,6 +5,7 @@ import DependencyGenerator import Functions 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) @@ -17,26 +18,26 @@ handleRecipeDir outputDir htmlTemplate indexName dir = do path <- joinPaths dir name path `copyTo` outputDir (base, ext) <- untupleDepGenM $ fileComponents name - thumbnailName <- concatStrings [ pure base, inject "-thumbnail.", pure ext ] + thumbnailName <- onToken concat [ pure base, inject "-thumbnail.", pure ext ] imageResized <- convertImage (openImage path) (inject (ResizeToWidth 800)) saveImage imageResized (joinPaths recipeDirOut thumbnailName) - concatTexts [ inject "

\n" - ] + onToken T.concat [ inject "

\n" + ] ingredienserHeadline <- inject "## Ingredienser" mdTemplate <- makeTemplate (readTextFile (joinPaths dir (inject "ret.md"))) ingredienserHeadline pandoc <- readMarkdown $ applyTemplate mdTemplate - $ concatTexts [ inject "

Opskrift fortsætter efter billedet.

\n" - , concatTexts htmlBodyImages - , inject "\n" - , pure ingredienserHeadline - ] + $ onToken T.concat [ inject "

Opskrift fortsætter efter billedet.

\n" + , onToken T.concat htmlBodyImages + , inject "\n" + , pure ingredienserHeadline + ] title <- extractTitle pandoc html <- applyTemplate htmlTemplate $ writeHtml pandoc