hakyll 4.9.5.1 → 4.9.6.0
raw patch · 9 files changed
+150/−65 lines, 9 filesdep ~optparse-applicativedep ~pandoc-citeproc
Dependency ranges changed: optparse-applicative, pandoc-citeproc
Files
- CHANGELOG.md +10/−0
- data/example/css/default.css +13/−13
- data/example/templates/default.html +9/−9
- data/example/templates/post.html +11/−8
- hakyll.cabal +2/−2
- src/Hakyll/Core/Compiler.hs +10/−1
- src/Hakyll/Core/File.hs +11/−3
- src/Hakyll/Main.hs +56/−28
- src/Hakyll/Web/Paginate.hs +28/−1
CHANGELOG.md view
@@ -4,6 +4,16 @@ # Releases +## Hakyll 4.9.6.0++- Tighten dependency on `pandoc-citeproc` (contribution by Mikhail Glushenkov)+- Enable using a custom parser for command line arguments (contribution by+ Alberto)+- Update examples to semantic HTML (contribution by Elie Génard)+- Better error for `cached` on non-existing file+- Provide an `$allPages$` key when doing pagination+- Preserve file metadata in `copyFileCompiler` (contribution by frederik-h)+ ## Hakyll 4.9.5.1 - Bump blaze-html dependency to 0.9
data/example/css/default.css view
@@ -5,25 +5,17 @@ width: 600px; } -div#header {+header { border-bottom: 2px solid black; margin-bottom: 30px; padding: 12px 0px 12px 0px; } -div#logo a {- color: black;- float: left;- font-size: 18px;- font-weight: bold;- text-decoration: none;-}--div#header #navigation {+nav { text-align: right; } -div#header #navigation a {+nav a { color: black; font-size: 18px; font-weight: bold;@@ -32,7 +24,7 @@ text-transform: uppercase; } -div#footer {+footer { border-top: solid 2px black; color: #555; font-size: 12px;@@ -49,8 +41,16 @@ font-size: 20px; } -div.info {+article .header { color: #555; font-size: 14px; font-style: italic;+}++.logo a {+ color: black;+ float: left;+ font-size: 18px;+ font-weight: bold;+ text-decoration: none; }
data/example/templates/default.html view
@@ -8,26 +8,26 @@ <link rel="stylesheet" href="/css/default.css" /> </head> <body>- <div id="header">- <div id="logo">+ <header>+ <div class="logo"> <a href="/">My Hakyll Blog</a> </div>- <div id="navigation">+ <nav> <a href="/">Home</a> <a href="/about.html">About</a> <a href="/contact.html">Contact</a> <a href="/archive.html">Archive</a>- </div>- </div>+ </nav>+ </header> - <div id="content">+ <main role="main"> <h1>$title$</h1> $body$- </div>+ </main> - <div id="footer">+ <footer> Site proudly generated by <a href="http://jaspervdj.be/hakyll">Hakyll</a>- </div>+ </footer> </body> </html>
data/example/templates/post.html view
@@ -1,8 +1,11 @@-<div class="info">- Posted on $date$- $if(author)$- by $author$- $endif$-</div>--$body$+<article>+ <section class="header">+ Posted on $date$+ $if(author)$+ by $author$+ $endif$+ </section>+ <section>+ $body$+ </section>+</article>
hakyll.cabal view
@@ -1,5 +1,5 @@ Name: hakyll-Version: 4.9.5.1+Version: 4.9.6.0 Synopsis: A static website compiler library Description:@@ -169,7 +169,7 @@ network >= 2.6 && < 2.7, network-uri >= 2.6 && < 2.7, pandoc >= 1.14 && < 1.20,- pandoc-citeproc >= 0.4 && < 0.11,+ pandoc-citeproc >= 0.4 && < 0.10.5, parsec >= 3.0 && < 3.2, process >= 1.0 && < 1.6, random >= 1.0 && < 1.2,
src/Hakyll/Core/Compiler.hs view
@@ -28,7 +28,7 @@ ---------------------------------------------------------------------------------import Control.Monad (when)+import Control.Monad (when, unless) import Data.Binary (Binary) import Data.ByteString.Lazy (ByteString) import Data.Typeable (Typeable)@@ -149,6 +149,10 @@ id' <- compilerUnderlying <$> compilerAsk store <- compilerStore <$> compilerAsk provider <- compilerProvider <$> compilerAsk++ -- Give a better error message when the resource is not there at all.+ unless (resourceExists provider id') $ fail $ itDoesntEvenExist id'+ let modified = resourceModified provider id' if modified then do@@ -165,6 +169,11 @@ error' progName = "Hakyll.Core.Compiler.cached: Cache corrupt! " ++ "Try running: " ++ progName ++ " clean"++ itDoesntEvenExist id' =+ "Hakyll.Core.Compiler.cached: You are trying to (perhaps " +++ "indirectly) use `cached` on a non-existing resource: there " +++ "is no file backing " ++ show id' --------------------------------------------------------------------------------
src/Hakyll/Core/File.hs view
@@ -1,5 +1,6 @@ -------------------------------------------------------------------------------- -- | Exports simple compilers to just copy files+{-# LANGUAGE CPP #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} module Hakyll.Core.File@@ -13,7 +14,12 @@ -------------------------------------------------------------------------------- import Data.Binary (Binary (..)) import Data.Typeable (Typeable)-import System.Directory (copyFile, doesFileExist,+#if MIN_VERSION_directory(1,2,6)+import System.Directory (copyFileWithMetadata)+#else+import System.Directory (copyFile)+#endif+import System.Directory (doesFileExist, renameFile) import System.FilePath ((</>)) import System.Random (randomIO)@@ -38,9 +44,11 @@ -------------------------------------------------------------------------------- instance Writable CopyFile where+#if MIN_VERSION_directory(1,2,6)+ write dst (Item _ (CopyFile src)) = copyFileWithMetadata src dst+#else write dst (Item _ (CopyFile src)) = copyFile src dst--+#endif -------------------------------------------------------------------------------- copyFileCompiler :: Compiler (Item CopyFile) copyFileCompiler = do
src/Hakyll/Main.hs view
@@ -1,10 +1,11 @@ -------------------------------------------------------------------------------- -- | Module providing the main hakyll function and command-line argument parsing {-# LANGUAGE CPP #-}-{-# LANGUAGE DeriveDataTypeable #-}+ module Hakyll.Main ( hakyll , hakyllWith+ , hakyllWithArgs , hakyllWithExitCode ) where @@ -16,7 +17,6 @@ ---------------------------------------------------------------------------------import Data.Monoid ((<>)) import Options.Applicative @@ -29,7 +29,7 @@ ----------------------------------------------------------------------------------- | This usualy is the function with which the user runs the hakyll compiler+-- | This usually is the function with which the user runs the hakyll compiler hakyll :: Rules a -> IO () hakyll = hakyllWith Config.defaultConfiguration @@ -39,26 +39,54 @@ hakyllWith :: Config.Configuration -> Rules a -> IO () hakyllWith conf rules = hakyllWithExitCode conf rules >>= exitWith +--------------------------------------------------------------------------------+-- | A variant of 'hakyll' which returns an 'ExitCode' hakyllWithExitCode :: Config.Configuration -> Rules a -> IO ExitCode-hakyllWithExitCode conf rules = do- args' <- customExecParser (prefs showHelpOnError) (info (helper <*> optionParser conf) (fullDesc <> progDesc (progName ++ " - Static site compiler created with Hakyll")))- let args'' = optCommand args'+hakyllWithExitCode conf rules = do+ args <- defaultParser conf+ hakyllWithExitCodeAndArgs conf args rules - let verbosity' = if verbosity args' then Logger.Debug else Logger.Message- check' =- if internal_links args'' then Check.InternalLinks else Check.All+--------------------------------------------------------------------------------+-- | A variant of 'hakyll' which expects a 'Configuration' and command-line+-- 'Options'. This gives freedom to implement your own parsing.+hakyllWithArgs :: Config.Configuration -> Options -> Rules a -> IO ()+hakyllWithArgs conf args rules =+ hakyllWithExitCodeAndArgs conf args rules >>= exitWith +--------------------------------------------------------------------------------+hakyllWithExitCodeAndArgs :: Config.Configuration ->+ Options -> Rules a -> IO ExitCode+hakyllWithExitCodeAndArgs conf args rules = do+ let args' = optCommand args+ verbosity' = if verbosity args then Logger.Debug else Logger.Message+ check =+ if internal_links args' then Check.InternalLinks else Check.All+ logger <- Logger.new verbosity'+ invokeCommands args' conf check logger rules - case args'' of- Build -> Commands.build conf logger rules- Check _ -> Commands.check conf logger check'- Clean -> Commands.clean conf logger >> ok- Deploy -> Commands.deploy conf- Preview p -> Commands.preview conf logger rules p >> ok- Rebuild -> Commands.rebuild conf logger rules- Server _ _ -> Commands.server conf logger (host args'') (port args'') >> ok- Watch _ p s -> Commands.watch conf logger (host args'') p (not s) rules >> ok+--------------------------------------------------------------------------------+defaultParser :: Config.Configuration -> IO Options+defaultParser conf =+ customExecParser (prefs showHelpOnError)+ (info (helper <*> optionParser conf)+ (fullDesc <> progDesc+ (progName ++ " - Static site compiler created with Hakyll")))+++--------------------------------------------------------------------------------+invokeCommands :: Command -> Config.Configuration ->+ Check.Check -> Logger.Logger -> Rules a -> IO ExitCode+invokeCommands args conf check logger rules =+ case args of+ Build -> Commands.build conf logger rules+ Check _ -> Commands.check conf logger check >> ok+ Clean -> Commands.clean conf logger >> ok+ Deploy -> Commands.deploy conf+ Preview p -> Commands.preview conf logger rules p >> ok+ Rebuild -> Commands.rebuild conf logger rules+ Server _ _ -> Commands.server conf logger (host args) (port args) >> ok+ Watch _ p s -> Commands.watch conf logger (host args) p (not s) rules >> ok where ok = return ExitSuccess @@ -80,7 +108,7 @@ deriving (Show) optionParser :: Config.Configuration -> Parser Options-optionParser conf = Options <$> verboseParser <*> (commandParser conf)+optionParser conf = Options <$> verboseParser <*> commandParser conf where verboseParser = switch (long "verbose" <> short 'v' <> help "Run in verbose mode") @@ -88,18 +116,18 @@ commandParser :: Config.Configuration -> Parser Command commandParser conf = subparser $ foldr ((<>) . produceCommand) mempty commands where- produceCommand (a,b) = command a (info (helper <*> (fst b)) (snd b))+ produceCommand (a,b) = command a (info (helper <*> fst b) (snd b)) portParser = option auto (long "port" <> help "Port to listen on" <> value (Config.previewPort conf)) hostParser = strOption (long "host" <> help "Host to bind on" <> value (Config.previewHost conf)) commands = [- ("build",(pure Build,fullDesc <> progDesc "Generate the site")),- ("check",(pure Check <*> switch (long "internal-links" <> help "Check internal links only"), fullDesc <> progDesc "Validate the site output")),- ("clean",(pure Clean,fullDesc <> progDesc "Clean up and remove cache")),- ("deploy",(pure Deploy,fullDesc <> progDesc "Upload/deploy your site")),- ("preview",(pure Preview <*> portParser,fullDesc <> progDesc "[DEPRECATED] Please use the watch command")),- ("rebuild",(pure Rebuild,fullDesc <> progDesc "Clean and build again")),- ("server",(pure Server <*> hostParser <*> portParser,fullDesc <> progDesc "Start a preview server")),- ("watch",(pure Watch <*> hostParser <*> portParser <*> switch (long "no-server" <> help "Disable the built-in web server"),fullDesc <> progDesc "Autocompile on changes and start a preview server. You can watch and recompile without running a server with --no-server."))+ ("build", (pure Build,fullDesc <> progDesc "Generate the site")),+ ("check", (pure Check <*> switch (long "internal-links" <> help "Check internal links only"), fullDesc <> progDesc "Validate the site output")),+ ("clean", (pure Clean,fullDesc <> progDesc "Clean up and remove cache")),+ ("deploy", (pure Deploy,fullDesc <> progDesc "Upload/deploy your site")),+ ("preview", (pure Preview <*> portParser,fullDesc <> progDesc "[DEPRECATED] Please use the watch command")),+ ("rebuild", (pure Rebuild,fullDesc <> progDesc "Clean and build again")),+ ("server", (pure Server <*> hostParser <*> portParser,fullDesc <> progDesc "Start a preview server")),+ ("watch", (pure Watch <*> hostParser <*> portParser <*> switch (long "no-server" <> help "Disable the built-in web server"),fullDesc <> progDesc "Autocompile on changes and start a preview server. You can watch and recompile without running a server with --no-server.")) ]
src/Hakyll/Web/Paginate.hs view
@@ -11,7 +11,8 @@ ---------------------------------------------------------------------------------import Control.Monad (forM_)+import Control.Applicative (empty)+import Control.Monad (forM_, forM) import qualified Data.Map as M import qualified Data.Set as S @@ -93,6 +94,18 @@ -- | A default paginate context which provides the following keys: -- --+-- * @firstPageNum@+-- * @firstPageUrl@+-- * @previousPageNum@+-- * @previousPageUrl@+-- * @nextPageNum@+-- * @nextPageUrl@+-- * @lastPageNum@+-- * @lastPageUrl@+-- * @currentPageNum@+-- * @currentPageUrl@+-- * @numPages@+-- * @allPages@ paginateContext :: Paginate -> PageNumber -> Context a paginateContext pag currentPage = mconcat [ field "firstPageNum" $ \_ -> otherPage 1 >>= num@@ -106,6 +119,20 @@ , field "currentPageNum" $ \i -> thisPage i >>= num , field "currentPageUrl" $ \i -> thisPage i >>= url , constField "numPages" $ show $ paginateNumPages pag+ , Context $ \k _ i -> case k of+ "allPages" -> do+ let ctx =+ field "isCurrent" (\n -> if fst (itemBody n) == currentPage then return "true" else empty) `mappend`+ field "num" (num . itemBody) `mappend`+ field "url" (url . itemBody)++ list <- forM [1 .. lastPage] $+ \n -> if n == currentPage then thisPage i else otherPage n+ items <- mapM makeItem list+ return $ ListField ctx items+ _ -> do+ empty+ ] where lastPage = paginateNumPages pag