1-- | Module providing the main hakyll function and command-line argument parsing
9import Control.Monad (when)
10import System.Directory (doesDirectoryExist, removeDirectoryRecursive)
11import System.Environment (getProgName, getArgs)
12import System.Process (system)
14import Hakyll.Core.Configuration
16import Hakyll.Core.Rules
19import Control.Applicative ((<$>))
20import Control.Concurrent (forkIO)
21import qualified Data.Set as S
23import Hakyll.Core.Resource
24import Hakyll.Core.Rules.Internal
25import Hakyll.Web.Preview.Poll
26import Hakyll.Web.Preview.Server
29-- | This usualy is the function with which the user runs the hakyll compiler
31hakyll :: RulesM a -> IO ()
32hakyll = hakyllWith defaultHakyllConfiguration
34-- | A variant of 'hakyll' which allows the user to specify a custom
37hakyllWith :: HakyllConfiguration -> RulesM a -> IO ()
38hakyllWith conf rules = do
41 ["build"] -> build conf rules
42 ["clean"] -> clean conf
44 ["preview"] -> preview conf rules 8000
45 ["preview", p] -> preview conf rules (read p)
46 ["rebuild"] -> rebuild conf rules
47 ["server"] -> server conf 8000
48 ["server", p] -> server conf (read p)
49 ["deploy"] -> deploy conf
54build :: HakyllConfiguration -> RulesM a -> IO ()
59-- | Remove the output directories
61clean :: HakyllConfiguration -> IO ()
63 remove $ destinationDirectory conf
64 remove $ storeDirectory conf
67 putStrLn $ "Removing " ++ dir ++ "..."
68 exists <- doesDirectoryExist dir
69 when exists $ removeDirectoryRecursive dir
71-- | Show usage information.
79 , "This is a Hakyll site generator program. You should always"
80 , "run it from the project root directory."
84 , name ++ " build Generate the site"
85 , name ++ " clean Clean up and remove cache"
86 , name ++ " help Show this message"
87 , name ++ " preview [port] Run a server and autocompile"
88 , name ++ " rebuild Clean up and build again"
89 , name ++ " server [port] Run a local test server"
90 , name ++ " deploy Upload/deploy your site"
100preview :: HakyllConfiguration -> RulesM a -> Int -> IO ()
102preview conf rules port = do
103 -- Fork a thread polling for changes
104 _ <- forkIO $ previewPoll conf update
106 -- Run the server in the main thread
109 update = map unResource . S.toList . rulesResources <$> run conf rules
111preview _ _ _ = previewServerDisabled
116rebuild :: HakyllConfiguration -> RulesM a -> IO ()
117rebuild conf rules = do
123server :: HakyllConfiguration -> Int -> IO ()
126 let destination = destinationDirectory conf
127 staticServer destination preServeHook port
129 preServeHook _ = return ()
131server _ _ = previewServerDisabled
136deploy :: HakyllConfiguration -> IO ()
138 _ <- system $ deployCommand conf
141-- | Print a warning message about the preview serving not being enabled
143#ifndef PREVIEW_SERVER
144previewServerDisabled :: IO ()
145previewServerDisabled =
149 , "The preview server is not enabled in the version of Hakyll. To"
150 , "enable it, set the flag to True and recompile Hakyll."
151 , "Alternatively, use an external tool to serve your site directory."
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list