2011-02-03 10:34:00 +00:00
|
|
|
-- | Module providing the main hakyll function and command-line argument parsing
|
|
|
|
--
|
|
|
|
module Hakyll.Main
|
|
|
|
( hakyll
|
|
|
|
, hakyllWith
|
|
|
|
) where
|
|
|
|
|
2011-02-03 13:18:09 +00:00
|
|
|
import Control.Monad (when)
|
|
|
|
import System.Environment (getProgName, getArgs)
|
|
|
|
import System.Directory (doesDirectoryExist, removeDirectoryRecursive)
|
|
|
|
|
2011-02-03 10:34:00 +00:00
|
|
|
import Hakyll.Core.Configuration
|
|
|
|
import Hakyll.Core.Run
|
|
|
|
import Hakyll.Core.Rules
|
2011-02-10 15:04:55 +00:00
|
|
|
import Hakyll.Web.Preview.Server
|
2011-02-03 10:34:00 +00:00
|
|
|
|
|
|
|
-- | This usualy is the function with which the user runs the hakyll compiler
|
|
|
|
--
|
|
|
|
hakyll :: Rules -> IO ()
|
2011-02-03 13:18:09 +00:00
|
|
|
hakyll = hakyllWith defaultHakyllConfiguration
|
2011-02-03 10:34:00 +00:00
|
|
|
|
|
|
|
-- | A variant of 'hakyll' which allows the user to specify a custom
|
|
|
|
-- configuration
|
|
|
|
--
|
|
|
|
hakyllWith :: HakyllConfiguration -> Rules -> IO ()
|
2011-02-03 13:18:09 +00:00
|
|
|
hakyllWith configuration rules = do
|
|
|
|
args <- getArgs
|
|
|
|
case args of
|
|
|
|
["build"] -> build configuration rules
|
|
|
|
["clean"] -> clean configuration
|
|
|
|
["help"] -> help
|
|
|
|
["preview"] -> putStrLn "Not implemented"
|
|
|
|
["preview", p] -> putStrLn "Not implemented"
|
|
|
|
["rebuild"] -> rebuild configuration rules
|
|
|
|
["server"] -> server configuration 8000
|
|
|
|
["server", p] -> server configuration (read p)
|
|
|
|
_ -> help
|
|
|
|
|
|
|
|
-- | Build the site
|
|
|
|
--
|
|
|
|
build :: HakyllConfiguration -> Rules -> IO ()
|
|
|
|
build = run
|
|
|
|
|
|
|
|
-- | Remove the output directories
|
|
|
|
--
|
|
|
|
clean :: HakyllConfiguration -> IO ()
|
|
|
|
clean configuration = do
|
|
|
|
remove $ destinationDirectory configuration
|
|
|
|
remove $ storeDirectory configuration
|
|
|
|
where
|
|
|
|
remove dir = do
|
|
|
|
putStrLn $ "Removing " ++ dir ++ "..."
|
|
|
|
exists <- doesDirectoryExist dir
|
|
|
|
when exists $ removeDirectoryRecursive dir
|
|
|
|
|
|
|
|
-- | Show usage information.
|
|
|
|
--
|
|
|
|
help :: IO ()
|
|
|
|
help = do
|
|
|
|
name <- getProgName
|
|
|
|
mapM_ putStrLn
|
|
|
|
[ "ABOUT"
|
|
|
|
, ""
|
|
|
|
, "This is a Hakyll site generator program. You should always"
|
|
|
|
, "run it from the project root directory."
|
|
|
|
, ""
|
|
|
|
, "USAGE"
|
|
|
|
, ""
|
|
|
|
, name ++ " build Generate the site"
|
|
|
|
, name ++ " clean Clean up and remove cache"
|
|
|
|
, name ++ " help Show this message"
|
|
|
|
, name ++ " preview [port] Run a server and autocompile"
|
|
|
|
, name ++ " rebuild Clean up and build again"
|
|
|
|
, name ++ " server [port] Run a local test server"
|
|
|
|
]
|
|
|
|
|
|
|
|
-- | Rebuild the site
|
|
|
|
--
|
|
|
|
rebuild :: HakyllConfiguration -> Rules -> IO ()
|
|
|
|
rebuild configuration rules = do
|
|
|
|
clean configuration
|
|
|
|
build configuration rules
|
|
|
|
|
|
|
|
-- | Start a server
|
|
|
|
--
|
|
|
|
server :: HakyllConfiguration -> Int -> IO ()
|
|
|
|
server configuration port = do
|
|
|
|
let destination = destinationDirectory configuration
|
|
|
|
staticServer destination preServeHook port
|
|
|
|
where
|
|
|
|
preServeHook _ = return ()
|