on master help sign in
add preview port Configuration field

Make it possible to specify the default port to listen on when the preview server is run. This is useful if another service on the system already runs on port 8000 (the default), since it's a hassle to keep providing the port overriding option. For example: ./site preview vs. ./site preview -p 4000

commit999252ece13cd695d65fed9cd01960f5ef3c60ff authorJorge Israel Peña <jorgepblank@gmail.com> dateThu 29 Aug 2013, 22:43 (13 years ago) parent94d7281
2 files changed+13−7
src/Hakyll/Core/Configuration.hs+5 src/Hakyll/Main.hs+8−7
src/Hakyll/Core/Configuration.hs+5
@@ -69,6 +69,10 @@ data Configuration = Configuration
6969 , -- | Use an in-memory cache for items. This is faster but uses more
7070 -- memory.
7171 inMemoryCache :: Bool
72+ , -- | Override default port for preview server. Default is 8000.
73+ -- One can also override the port as a command line argument:
74+ -- ./site preview -p 1234
75+ previewPort :: Int
7276 }
7377
7478--------------------------------------------------------------------------------
@@ -87,6 +91,7 @@ defaultConfiguration = Configuration
8791 , deployCommand = "echo 'No deploy command specified' && exit 1"
8892 , deploySite = system . deployCommand
8993 , inMemoryCache = True
94+ , previewPort = 8000
9095 }
9196 where
9297 ignoreFile' path
src/Hakyll/Main.hs+8−7
@@ -34,7 +34,7 @@ hakyll = hakyllWith Config.defaultConfiguration
3434-- configuration
3535hakyllWith :: Config.Configuration -> Rules a -> IO ()
3636hakyllWith conf rules = do
37− args' <- cmdArgs hakyllArgs
37+ args' <- cmdArgs (hakyllArgs conf)
3838
3939 let verbosity' = if verbose args' then Logger.Debug else Logger.Message
4040 check' =
@@ -55,7 +55,7 @@ hakyllWith conf rules = do
5555--------------------------------------------------------------------------------
5656-- | Show usage information.
5757showHelp :: IO ()
58−showHelp = print $ CA.helpText [] CA.HelpFormatOne $ cmdArgsMode hakyllArgs
58+showHelp = print $ CA.helpText [] CA.HelpFormatOne $ cmdArgsMode (hakyllArgs Config.defaultConfiguration)
5959
6060
6161--------------------------------------------------------------------------------
@@ -73,22 +73,23 @@ data HakyllArgs
7373
7474
7575--------------------------------------------------------------------------------
76−hakyllArgs :: HakyllArgs
77−hakyllArgs = modes
76+hakyllArgs :: Config.Configuration -> HakyllArgs
77+hakyllArgs conf = modes
7878 [ (Build $ verboseFlag def) &= help "Generate the site"
7979 , (Check (verboseFlag def) (False &= help "Check internal links only")) &=
8080 help "Validate the site output"
8181 , (Clean $ verboseFlag def) &= help "Clean up and remove cache"
8282 , (Deploy $ verboseFlag def) &= help "Upload/deploy your site"
8383 , (Help $ verboseFlag def) &= help "Show this message" &= auto
84− , (Preview (verboseFlag def) (portFlag 8000)) &=
84+ , (Preview (verboseFlag def) (portFlag defaultPort)) &=
8585 help "[Deprecated] Please use the watch command"
8686 , (Rebuild $ verboseFlag def) &= help "Clean and build again"
87− , (Server (verboseFlag def) (portFlag 8000)) &=
87+ , (Server (verboseFlag def) (portFlag defaultPort)) &=
8888 help "Start a preview server"
89− , (Watch (verboseFlag def) (portFlag 8000) (noServerFlag False) &=
89+ , (Watch (verboseFlag def) (portFlag defaultPort) (noServerFlag False) &=
9090 help "Autocompile on changes and start a preview server. You can watch and recompile without running a server with --no-server.")
9191 ] &= help "Hakyll static site compiler" &= program progName
92+ where defaultPort = Config.previewPort conf
9293
9394
9495--------------------------------------------------------------------------------