From 543cba90f6efba8508d2feb3377b1a9f5f428c1a Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 24 Mar 2013 21:47:05 +0100 Subject: Allow overriding the `deploy` command with Haskell code By overriding `deploySite` with a `Configuration -> IO ()` code, the user can execute Haskell code to deploy the site rather than shell code. The default behaviour honors the `deployCommand` configuration field and is backward compatible. --- src/Hakyll/Commands.hs | 5 +---- src/Hakyll/Core/Configuration.hs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Hakyll/Commands.hs b/src/Hakyll/Commands.hs index 4c60783..6e0b9f2 100644 --- a/src/Hakyll/Commands.hs +++ b/src/Hakyll/Commands.hs @@ -14,7 +14,6 @@ module Hakyll.Commands -------------------------------------------------------------------------------- import System.Exit (ExitCode (ExitSuccess), exitWith) -import System.Process (system) -------------------------------------------------------------------------------- @@ -109,9 +108,7 @@ server _ _ = previewServerDisabled -------------------------------------------------------------------------------- -- | Upload the site deploy :: Configuration -> IO () -deploy conf = do - _ <- system $ deployCommand conf - return () +deploy conf = deploySite conf conf -------------------------------------------------------------------------------- diff --git a/src/Hakyll/Core/Configuration.hs b/src/Hakyll/Core/Configuration.hs index 5382b6d..480c6c4 100644 --- a/src/Hakyll/Core/Configuration.hs +++ b/src/Hakyll/Core/Configuration.hs @@ -8,9 +8,11 @@ module Hakyll.Core.Configuration -------------------------------------------------------------------------------- +import Control.Monad (void) import Data.Default (Default(..)) import Data.List (isPrefixOf, isSuffixOf) import System.FilePath (normalise, takeFileName) +import System.Process (system) -------------------------------------------------------------------------------- @@ -52,6 +54,16 @@ data Configuration = Configuration -- > ./site deploy -- deployCommand :: String + , -- | Function to deploy the site from Haskell. + -- + -- By default, this command executes the shell command stored in + -- 'deployCommand'. If you override it, 'deployCommand' will not + -- be used implicitely. + -- + -- The 'Configuration' object is passed as a parameter to this + -- function. + -- + deploySite :: Configuration -> IO () , -- | Use an in-memory cache for items. This is faster but uses more -- memory. inMemoryCache :: Bool @@ -71,6 +83,7 @@ defaultConfiguration = Configuration , providerDirectory = "." , ignoreFile = ignoreFile' , deployCommand = "echo 'No deploy command specified'" + , deploySite = void . system . deployCommand , inMemoryCache = True } where -- cgit v1.2.3