module Main where import Control.Exception import Data.Either import Data.List import Data.Maybe import Options.Applicative import System.Directory import System.FilePath import System.Environment (getArgs) import System.Process (readProcess) import Heckle import Files data Command = Build | Init withInfo :: InfoMod a -> Parser a -> ParserInfo a withInfo im p = info (helper <*> p) im infixr 1 ==> (==>) = withInfo . progDesc mainFlags :: ParserInfo Command mainFlags = withInfo (fullDesc <> progDesc "heckle: a simple, configurable static site generator") parser where parser :: Parser Command parser = subparser $ mconcat [ command "build" $ "Generate site" ==> pure Build , command "init" $ "Make new site template" ==> pure Init ] buildSite :: IO () buildSite = do putStrLn "Reading directory and turning into native posts" postsToBeCreated <- mapM fileToPost =<< getDirectoryContents "posts" let posts = reverse . sort . rights $ postsToBeCreated putStrLn $ "Number of posts found: " ++ show (length posts) putStrLn "Writing markdown files into template HTML" template <- readFile "template.html.hkl" sequence $ mapMaybe (writeHTML template) posts putStrLn "Creating HTML