diff options
-rw-r--r-- | .ghci | 2 | ||||
-rw-r--r-- | hakyll.cabal | 18 | ||||
-rw-r--r-- | src/Hakyll/Main.hs | 42 |
3 files changed, 52 insertions, 10 deletions
@@ -1 +1 @@ -:set -isrc -isrc-interval -itests -idist/build/autogen +:set -isrc -isrc-interval -itests -idist/build/autogen -DPREVIEW_SERVER diff --git a/hakyll.cabal b/hakyll.cabal index 8871ee8..16f26e0 100644 --- a/hakyll.cabal +++ b/hakyll.cabal @@ -50,6 +50,10 @@ Source-Repository head Type: git Location: git://github.com/jaspervdj/hakyll.git +Flag previewServer + Description: Include the preview server + default: True + Library Ghc-Options: -Wall Hs-Source-Dirs: src @@ -72,8 +76,6 @@ Library process >= 1.0 && < 1.4, regex-base >= 0.93 && < 1.0, regex-pcre >= 0.93 && < 1.0, - snap-core >= 0.5.1 && < 0.6, - snap-server >= 0.5.1 && < 0.6, tagsoup >= 0.12 && < 0.13, time >= 1.1 && < 1.3, unix >= 2.4 && < 2.6 @@ -113,8 +115,6 @@ Library Hakyll.Web.Page.Read Hakyll.Web.Pandoc Hakyll.Web.Pandoc.FileType - Hakyll.Web.Preview.Poll - Hakyll.Web.Preview.Server Hakyll.Web.RelativizeUrls Hakyll.Web.Tags Hakyll.Web.Template @@ -131,3 +131,13 @@ Library Hakyll.Web.Template.Read.Hakyll Hakyll.Web.Template.Read.Hamlet Paths_hakyll + + If flag(previewServer) + Build-depends: + snap-core >= 0.5.1 && < 0.6, + snap-server >= 0.5.1 && < 0.6 + Cpp-Options: + -DPREVIEW_SERVER + Other-Modules: + Hakyll.Web.Preview.Poll + Hakyll.Web.Preview.Server diff --git a/src/Hakyll/Main.hs b/src/Hakyll/Main.hs index ef5c4c8..d97dc31 100644 --- a/src/Hakyll/Main.hs +++ b/src/Hakyll/Main.hs @@ -1,25 +1,30 @@ -- | Module providing the main hakyll function and command-line argument parsing -- +{-# LANGUAGE CPP #-} module Hakyll.Main ( hakyll , hakyllWith ) where -import Control.Applicative ((<$>)) -import Control.Concurrent (forkIO) import Control.Monad (when) import System.Directory (doesDirectoryExist, removeDirectoryRecursive) import System.Environment (getProgName, getArgs) import System.Process (system) -import qualified Data.Set as S import Hakyll.Core.Configuration -import Hakyll.Core.Resource import Hakyll.Core.Run import Hakyll.Core.Rules + +#ifdef PREVIEW_SERVER +import Control.Applicative ((<$>)) +import Control.Concurrent (forkIO) +import qualified Data.Set as S + +import Hakyll.Core.Resource import Hakyll.Core.Rules.Internal import Hakyll.Web.Preview.Poll import Hakyll.Web.Preview.Server +#endif -- | This usualy is the function with which the user runs the hakyll compiler -- @@ -83,11 +88,17 @@ help = do , name ++ " rebuild Clean up and build again" , name ++ " server [port] Run a local test server" , name ++ " deploy Upload/deploy your site" + , "" ] +#ifndef PREVIEW_SERVER + previewServerDisabled +#endif + -- | Preview the site -- preview :: HakyllConfiguration -> RulesM a -> Int -> IO () +#ifdef PREVIEW_SERVER preview conf rules port = do -- Fork a thread polling for changes _ <- forkIO $ previewPoll conf update @@ -96,6 +107,9 @@ preview conf rules port = do server conf port where update = map unResource . S.toList . rulesResources <$> run conf rules +#else +preview _ _ _ = previewServerDisabled +#endif -- | Rebuild the site -- @@ -107,15 +121,33 @@ rebuild conf rules = do -- | Start a server -- server :: HakyllConfiguration -> Int -> IO () +#ifdef PREVIEW_SERVER server conf port = do let destination = destinationDirectory conf staticServer destination preServeHook port where preServeHook _ = return () +#else +server _ _ = previewServerDisabled +#endif --- Upload the site +-- | Upload the site -- deploy :: HakyllConfiguration -> IO () deploy conf = do _ <- system $ deployCommand conf return () + +-- | Print a warning message about the preview serving not being enabled +-- +#ifndef PREVIEW_SERVER +previewServerDisabled :: IO () +previewServerDisabled = + mapM_ putStrLn + [ "PREVIEW SERVER" + , "" + , "The preview server is not enabled in the version of Hakyll. To" + , "enable it, set the flag to True and recompile Hakyll." + , "Alternatively, use an external tool to serve your site directory." + ] +#endif |