@@ -5,17 +5,87 @@ module Hakyll.Main
5 , hakyllWith
5 , hakyllWith
8+import Control.Monad (when)
9+import System.Environment (getProgName, getArgs)
10+import System.Directory (doesDirectoryExist, removeDirectoryRecursive)
8import Hakyll.Core.Configuration
12import Hakyll.Core.Configuration
9import Hakyll.Core.Run
13import Hakyll.Core.Run
10import Hakyll.Core.Rules
14import Hakyll.Core.Rules
15+import Hakyll.Network.Server
12-- | This usualy is the function with which the user runs the hakyll compiler
17-- | This usualy is the function with which the user runs the hakyll compiler
14hakyll :: Rules -> IO ()
19hakyll :: Rules -> IO ()
15−hakyll = run defaultHakyllConfiguration
20+hakyll = hakyllWith defaultHakyllConfiguration
17-- | A variant of 'hakyll' which allows the user to specify a custom
22-- | A variant of 'hakyll' which allows the user to specify a custom
18-- configuration
23-- configuration
20hakyllWith :: HakyllConfiguration -> Rules -> IO ()
25hakyllWith :: HakyllConfiguration -> Rules -> IO ()
21−hakyllWith = run
26+hakyllWith configuration rules = do
29+ ["build"] -> build configuration rules
30+ ["clean"] -> clean configuration
32+ ["preview"] -> putStrLn "Not implemented"
33+ ["preview", p] -> putStrLn "Not implemented"
34+ ["rebuild"] -> rebuild configuration rules
35+ ["server"] -> server configuration 8000
36+ ["server", p] -> server configuration (read p)
41+build :: HakyllConfiguration -> Rules -> IO ()
44+-- | Remove the output directories
46+clean :: HakyllConfiguration -> IO ()
47+clean configuration = do
48+ remove $ destinationDirectory configuration
49+ remove $ storeDirectory configuration
52+ putStrLn $ "Removing " ++ dir ++ "..."
53+ exists <- doesDirectoryExist dir
54+ when exists $ removeDirectoryRecursive dir
56+-- | Show usage information.
64+ , "This is a Hakyll site generator program. You should always"
65+ , "run it from the project root directory."
69+ , name ++ " build Generate the site"
70+ , name ++ " clean Clean up and remove cache"
71+ , name ++ " help Show this message"
72+ , name ++ " preview [port] Run a server and autocompile"
73+ , name ++ " rebuild Clean up and build again"
74+ , name ++ " server [port] Run a local test server"
79+rebuild :: HakyllConfiguration -> Rules -> IO ()
80+rebuild configuration rules = do
82+ build configuration rules
86+server :: HakyllConfiguration -> Int -> IO ()
87+server configuration port = do
88+ let destination = destinationDirectory configuration
89+ staticServer destination preServeHook port
91+ preServeHook _ = return ()