packages feed

hakyll 2.1 → 2.1.1

raw patch · 10 files changed

+66/−54 lines, 10 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Text.Hakyll.HakyllMonad: previewPollDelay :: HakyllConfiguration -> Int
+ Text.Hakyll.ContextManipulations: changeUrl :: (String -> String) -> HakyllAction Context Context
- Network.Hakyll.SimpleServer: simpleServer :: PortNumber -> FilePath -> IO ()
+ Network.Hakyll.SimpleServer: simpleServer :: PortNumber -> FilePath -> IO () -> IO ()
- Text.Hakyll.HakyllAction: HakyllAction :: [FilePath] -> Maybe (Hakyll FilePath) -> (a -> Hakyll b) -> HakyllAction a b
+ Text.Hakyll.HakyllAction: HakyllAction :: [FilePath] -> Either (Hakyll FilePath) (Hakyll FilePath -> Hakyll FilePath) -> (a -> Hakyll b) -> HakyllAction a b
- Text.Hakyll.HakyllAction: actionUrl :: HakyllAction a b -> Maybe (Hakyll FilePath)
+ Text.Hakyll.HakyllAction: actionUrl :: HakyllAction a b -> Either (Hakyll FilePath) (Hakyll FilePath -> Hakyll FilePath)
- Text.Hakyll.HakyllMonad: HakyllConfiguration :: String -> Context -> FilePath -> FilePath -> Bool -> Int -> ParserState -> WriterOptions -> HakyllConfiguration
+ Text.Hakyll.HakyllMonad: HakyllConfiguration :: String -> Context -> FilePath -> FilePath -> Bool -> ParserState -> WriterOptions -> HakyllConfiguration

Files

hakyll.cabal view
@@ -1,5 +1,5 @@ Name:               hakyll-Version:            2.1+Version:            2.1.1  Synopsis:           A simple static site generator library. Description:        A simple static site generator library, mainly aimed at
src/Network/Hakyll/SimpleServer.hs view
@@ -102,7 +102,8 @@ createGetResponse request = do     -- Construct the complete fileName of the requested resource.     config <- ask-    let uri = requestURI request+    let -- Drop everything after a '?'.+        uri = takeWhile ((/=) '?') $ requestURI request         log' = writeChan (logChannel config)     isDirectory <- liftIO $ doesDirectoryExist $ documentRoot config ++ uri     let fileName =@@ -187,8 +188,12 @@  -- | Start a simple http server on the given 'PortNumber', serving the given --   directory.-simpleServer :: PortNumber -> FilePath -> IO ()-simpleServer port root = do+--+simpleServer :: PortNumber  -- ^ Port to listen on.+             -> FilePath    -- ^ Root directory to serve.+             -> IO ()       -- ^ Optional pre-respond action.+             -> IO ()+simpleServer port root preRespond = do     -- Channel to send logs to     logChan <- newChan @@ -199,6 +204,7 @@            -- When a client connects, respond in a separate thread.         listen socket = do (handle, _, _) <- accept socket+                           preRespond                            forkIO (runReaderT (respond handle) config)      -- Handle logging in a separate thread
src/Text/Hakyll.hs view
@@ -1,4 +1,4 @@--- | This is the main Hakyll module, exporting the important @hakyl@ function.+-- | This is the main Hakyll module, exporting the important @hakyll@ function. -- --   Most configurations would use this @hakyll@ function more or less as the --   main function:@@ -14,20 +14,18 @@     ) where  import Control.Monad.Reader (runReaderT, liftIO, ask)-import Control.Concurrent (forkIO, threadDelay) import Control.Monad (when) import qualified Data.Map as M import System.Environment (getArgs, getProgName) import System.Directory (doesDirectoryExist, removeDirectoryRecursive)-import System.Time (getClockTime)  import Text.Pandoc  import Network.Hakyll.SimpleServer (simpleServer) import Text.Hakyll.HakyllMonad-import Text.Hakyll.File  -- | The default reader options for pandoc parsing.+-- defaultPandocParserState :: ParserState defaultPandocParserState = defaultParserState     { -- The following option causes pandoc to read smart typography, a nice@@ -36,6 +34,7 @@     }  -- | The default writer options for pandoc rendering.+-- defaultPandocWriterOptions :: WriterOptions defaultPandocWriterOptions = defaultWriterOptions     { -- This option causes literate haskell to be written using '>' marks in@@ -44,6 +43,7 @@     }  -- | The default hakyll configuration.+-- defaultHakyllConfiguration :: HakyllConfiguration defaultHakyllConfiguration = HakyllConfiguration     { absoluteUrl         = ""@@ -51,14 +51,14 @@     , siteDirectory       = "_site"     , cacheDirectory      = "_cache"     , enableIndexUrl      = False-    , previewPollDelay    = 1000000     , pandocParserState   = defaultPandocParserState     , pandocWriterOptions = defaultPandocWriterOptions     }  -- | Main function to run Hakyll with the default configuration. The---   absolute URL is only used in certain cases, for example RSS feeds et---   cetera.+-- absolute URL is only used in certain cases, for example RSS feeds et+-- cetera.+-- hakyll :: String    -- ^ Absolute URL of your site. Used in certain cases.        -> Hakyll () -- ^ You code.        -> IO ()@@ -67,20 +67,22 @@     configuration = defaultHakyllConfiguration { absoluteUrl = absolute }  -- | Main function to run hakyll with a custom configuration.+-- hakyllWithConfiguration :: HakyllConfiguration -> Hakyll () -> IO () hakyllWithConfiguration configuration buildFunction = do     args <- getArgs     let f = case args of ["build"]      -> buildFunction                          ["clean"]      -> clean-                         ["preview", p] -> preview buildFunction (read p)-                         ["preview"]    -> preview buildFunction 8000+                         ["preview", p] -> server (read p) buildFunction+                         ["preview"]    -> server 8000 buildFunction                          ["rebuild"]    -> clean >> buildFunction-                         ["server", p]  -> server (read p)-                         ["server"]     -> server 8000+                         ["server", p]  -> server (read p) (return ())+                         ["server"]     -> server 8000 (return ())                          _              -> help     runReaderT f configuration  -- | Clean up directories.+-- clean :: Hakyll () clean = do askHakyll siteDirectory >>= remove'            askHakyll cacheDirectory >>= remove'@@ -89,24 +91,8 @@                               exists <- doesDirectoryExist dir                               when exists $ removeDirectoryRecursive dir --- | Autocompile mode.-preview :: Hakyll () -> Integer -> Hakyll ()-preview buildFunction port = do-    buildFunction-    _ <- startServer-    liftIO getClockTime >>= run-  where-    startServer = do configuration <- ask-                     liftIO $ forkIO $ runReaderT (server port) configuration-    run time = do delay <- askHakyll previewPollDelay-                  liftIO $ threadDelay delay-                  contents <- getRecursiveContents "."-                  valid <- isMoreRecent time contents-                  if valid then run time-                           else do buildFunction-                                   liftIO getClockTime >>= run- -- | Show usage information.+-- help :: Hakyll () help = liftIO $ do     name <- getProgName@@ -122,5 +108,12 @@              ++ name ++ " server [port]   Run a local test server.\n"  -- | Start a server at the given port number.-server :: Integer -> Hakyll ()-server p = askHakyll siteDirectory >>= liftIO . simpleServer (fromIntegral p)+--+server :: Integer    -- ^ Port number to serve on.+       -> Hakyll ()  -- ^ Pre-respond action.+       -> Hakyll ()+server port preRespond = do +    configuration <- ask+    root <- askHakyll siteDirectory+    let preRespondIO = runReaderT preRespond configuration+    liftIO $ simpleServer (fromIntegral port) root preRespondIO
src/Text/Hakyll/ContextManipulations.hs view
@@ -3,12 +3,14 @@ module Text.Hakyll.ContextManipulations     ( renderValue     , changeValue+    , changeUrl     , copyValue     , renderDate     , changeExtension     , renderBody     ) where +import Control.Monad (liftM) import Control.Arrow (arr) import System.Locale (defaultTimeLocale) import System.FilePath (takeFileName, addExtension, dropExtension)@@ -18,7 +20,7 @@ import qualified Data.Map as M  import Text.Hakyll.Regex (substituteRegex)-import Text.Hakyll.HakyllAction (HakyllAction)+import Text.Hakyll.HakyllAction (HakyllAction (..)) import Text.Hakyll.Context (Context)  -- | Do something with a value in a @Context@, but keep the old value as well.@@ -42,6 +44,14 @@             -> (String -> String) -- ^ Function to apply on the value.             -> HakyllAction Context Context changeValue key = renderValue key key++-- | Change the URL of a page. This requires a special function, so dependency+-- handling can happen correctly.+-- +changeUrl :: (String -> String)            -- ^ Function to change URL with.+          -> HakyllAction Context Context  -- ^ Resulting action.+changeUrl f = let action = changeValue "url" f+              in action {actionUrl = Right $ liftM f}  -- | Copy a value from one key to another in a @Context@. copyValue :: String -- ^ Source key.
src/Text/Hakyll/CreateContext.hs view
@@ -11,7 +11,7 @@  import qualified Data.Map as M import Control.Arrow (second)-import Control.Monad (liftM2, mplus)+import Control.Monad (liftM2) import Control.Applicative ((<$>))  import Text.Hakyll.File@@ -25,7 +25,7 @@ createPage :: FilePath -> HakyllAction () Context createPage path = HakyllAction     { actionDependencies = [path]-    , actionUrl          = Just $ toUrl path+    , actionUrl          = Left $ toUrl path     , actionFunction     = const (readPage path)     } @@ -41,7 +41,7 @@                  -> HakyllAction () Context createCustomPage url association = HakyllAction     { actionDependencies = dataDependencies-    , actionUrl          = Just $ return url+    , actionUrl          = Left $ return url     , actionFunction     = \_ -> M.fromList <$> assoc'     }   where@@ -78,7 +78,7 @@         -> HakyllAction () Context combine x y = HakyllAction     { actionDependencies = actionDependencies x ++ actionDependencies y-    , actionUrl          = actionUrl x `mplus` actionUrl y+    , actionUrl          = actionUrl x     , actionFunction     = \_ ->         liftM2 M.union (runHakyllAction x) (runHakyllAction y)     }@@ -90,7 +90,7 @@                -> HakyllAction () Context                -> HakyllAction () Context combineWithUrl url x y = combine'-    { actionUrl          = Just $ return url+    { actionUrl          = Left $ return url     , actionFunction     = \_ -> M.insert "url" url <$> runHakyllAction combine'     }   where
src/Text/Hakyll/HakyllAction.hs view
@@ -11,7 +11,7 @@  import Control.Arrow import Control.Category-import Control.Monad ((<=<), mplus, unless)+import Control.Monad ((<=<), unless) import Control.Monad.Reader (liftIO) import Prelude hiding ((.), id) import System.IO (hPutStrLn, stderr)@@ -24,7 +24,8 @@     { -- | Dependencies of the @HakyllAction@.       actionDependencies :: [FilePath]     , -- | URL pointing to the result of this @HakyllAction@.-      actionUrl          :: Maybe (Hakyll FilePath)+      actionUrl          :: Either (Hakyll FilePath)+                                   (Hakyll FilePath -> Hakyll FilePath)     , -- | The actual render function.       actionFunction     :: a -> Hakyll b     }@@ -45,7 +46,7 @@                        -> HakyllAction () b -- ^ The resulting action. createFileHakyllAction path action = HakyllAction     { actionDependencies = [path]-    , actionUrl          = Just $ return path+    , actionUrl          = Left $ return path     , actionFunction     = const action     } @@ -60,8 +61,8 @@                         -> Hakyll ()          -- ^ Empty result. runHakyllActionIfNeeded action = do     url <- case actionUrl action of-        (Just u) -> u-        Nothing  -> error "No url when checking dependencies."+        Left u  -> u+        Right _ -> error "No url when checking dependencies."     destination <- toDestination url     valid <- isFileMoreRecent destination $ actionDependencies action     unless valid $ do liftIO $ hPutStrLn stderr $ "Rendering " ++ destination@@ -76,13 +77,17 @@ instance Category HakyllAction where     id = HakyllAction         { actionDependencies = []-        , actionUrl          = Nothing+        , actionUrl          = Right id         , actionFunction     = return         }      x . y = HakyllAction         { actionDependencies = actionDependencies x ++ actionDependencies y-        , actionUrl          = actionUrl x `mplus` actionUrl y+        , actionUrl          = case actionUrl x of+            Left ux  -> Left ux+            Right fx -> case actionUrl y of+                Left uy  -> Left (fx uy)+                Right fy -> Right (fx . fy)         , actionFunction     = actionFunction x <=< actionFunction y         } 
src/Text/Hakyll/HakyllMonad.hs view
@@ -30,8 +30,6 @@       cacheDirectory      :: FilePath     , -- | Enable index links.       enableIndexUrl      :: Bool-    , -- | Delay between polls in preview mode.-      previewPollDelay    :: Int     , -- | Pandoc parsing options       pandocParserState   :: ParserState     , -- | Pandoc writer options
src/Text/Hakyll/Paginate.hs view
@@ -61,8 +61,8 @@   where     -- Create a link with a given label, taken from the configuration.     linkWithLabel f r = Right $ case actionUrl r of-        Just l  -> createSimpleHakyllAction $ link (f configuration) <$> l-        Nothing -> error "No link found for pagination."+        Left l  -> createSimpleHakyllAction $ link (f configuration) <$> l+        Right _ -> error "No link found for pagination."      -- The main function that creates combined renderables by recursing over     -- the list of items.
src/Text/Hakyll/Render.hs view
@@ -40,7 +40,7 @@        -> HakyllAction Context Context -- ^ The render computation. render templatePath = HakyllAction     { actionDependencies = [templatePath]-    , actionUrl          = Nothing+    , actionUrl          = Right id     , actionFunction     = \context ->         flip pureRender context <$> readTemplate templatePath     }@@ -59,7 +59,7 @@                 -> HakyllAction () String renderAndConcat templatePaths renderables = HakyllAction     { actionDependencies = renders >>= actionDependencies-    , actionUrl          = Nothing+    , actionUrl          = Right id     , actionFunction     = actionFunction'     }   where
src/Text/Hakyll/Tags.hs view
@@ -68,7 +68,7 @@         -> HakyllAction () TagMap readMap getTagsFunction identifier paths = HakyllAction     { actionDependencies = paths-    , actionUrl          = Nothing+    , actionUrl          = Right id     , actionFunction     = actionFunction'     }    where