heckle-0.1.0.0: src/Main.hs
module Main where
import System.Directory
import Data.Either
import Data.List
import System.Environment (getArgs)
import System.Process (readProcess)
import Heckle
main = do
args <- getArgs
case args of
["build"] -> do
putStrLn "Building"
----get all md files from directory
putStrLn "Getting directory contents"
fileNames <- fmap (rights . map getMD) (getDirectoryContents "posts")
--turn the list of files into a list of posts
putStrLn "Turning directory contents into posts"
postsToBeCreated <- (mapM filenameToPost fileNames)
--print postsToBeCreated
--postsToBeCreated <- (mapM fileNameToPost fileNames)
let posts = (reverse . rights) postsToBeCreated -- need to sort here when you add in support for dates
let brokenPosts = lefts postsToBeCreated
if length (brokenPosts) > 1
then print brokenPosts
else putStrLn "All posts are well formed"
--print posts
--convert posts to their html
mapM_ writeHTML posts
--generate a ul from the list of posts
putStrLn "Turning posts into an HTML element"
let generatedHtml = postsToHtml posts
print generatedHtml
--read the layout file
putStrLn "Reading the layout file"
layoutFile <- readFile "index.html.hkl"
--put the ul into the layout file
putStrLn "Inserting HTML element into layout file"
let injectedOutput = layoutFile `injectPosts` generatedHtml
case injectedOutput of
(Left e) -> putStrLn e
(Right s) -> do
--put the results into the index.html file
putStrLn "Writing resulting file into index.html"
writeFile "index.html" s
putStrLn "Success building!"
_ -> print "That's not a valid command"