1-- | This is the main Hakyll module, exporting the important @hakyl@ function.
3-- Most configurations would use this @hakyll@ function more or less as the
7-- > directory css "css"
8-- > directory static "images"
11 ( defaultHakyllConfiguration
13 , hakyllWithConfiguration
16import Control.Monad.Reader (runReaderT, liftIO, ask)
17import Control.Concurrent (forkIO, threadDelay)
18import Control.Monad (when)
19import qualified Data.Map as M
20import System.Environment (getArgs, getProgName)
21import System.Directory (doesDirectoryExist, removeDirectoryRecursive)
22import System.Time (getClockTime)
24import Network.Hakyll.SimpleServer (simpleServer)
25import Text.Hakyll.Hakyll
26import Text.Hakyll.File
28-- | The default hakyll configuration.
29defaultHakyllConfiguration :: HakyllConfiguration
30defaultHakyllConfiguration = HakyllConfiguration
31 { additionalContext = M.empty
32 , siteDirectory = "_site"
33 , cacheDirectory = "_cache"
34 , enableIndexUrl = False
35 , previewPollDelay = 1000000
38-- | Main function to run Hakyll with the default configuration.
39hakyll :: Hakyll () -> IO ()
40hakyll = hakyllWithConfiguration defaultHakyllConfiguration
42-- | Main function to run hakyll with a custom configuration.
43hakyllWithConfiguration :: HakyllConfiguration -> Hakyll () -> IO ()
44hakyllWithConfiguration configuration buildFunction = do
46 let f = case args of ["build"] -> buildFunction
48 ["preview", p] -> preview buildFunction (read p)
49 ["preview"] -> preview buildFunction 8000
50 ["server", p] -> server (read p)
51 ["server"] -> server 8000
53 runReaderT f configuration
55-- | Clean up directories.
57clean = do askHakyll siteDirectory >>= remove'
58 askHakyll cacheDirectory >>= remove'
60 remove' dir = liftIO $ do putStrLn $ "Removing " ++ dir ++ "..."
61 exists <- doesDirectoryExist dir
62 when exists $ removeDirectoryRecursive dir
65preview :: Hakyll () -> Integer -> Hakyll ()
66preview buildFunction port = do
69 liftIO getClockTime >>= run
71 startServer = do configuration <- ask
72 liftIO $ forkIO $ runReaderT (server port) configuration
73 run time = do delay <- askHakyll previewPollDelay
74 liftIO $ threadDelay delay
75 contents <- getRecursiveContents "."
76 valid <- isMoreRecent time contents
77 if valid then run time
79 liftIO getClockTime >>= run
81-- | Show usage information.
85 putStrLn $ "This is a Hakyll site generator program. You should always\n"
86 ++ "run it from the project root directory.\n"
89 ++ name ++ " build Generate the site.\n"
90 ++ name ++ " clean Clean up and remove cache.\n"
91 ++ name ++ " help Show this message.\n"
92 ++ name ++ " preview [port] Run a server and autocompile.\n"
93 ++ name ++ " server [port] Run a local test server.\n"
95-- | Start a server at the given port number.
96server :: Integer -> Hakyll ()
97server p = askHakyll siteDirectory >>= liftIO . simpleServer (fromIntegral p)
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