diff --git a/CHANGELOG.md b/CHANGELOG.md index c65c61022..9ed214440 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,18 @@ title: Releases # Releases +## Unreleased + +- Fixed an issue where compressing CSS with `clamp` expressions would + result in invalid CSS (#1021) (contribution by Laurent P. René de Cotret) + +## Hakyll 4.16.3.0 (2024-10-24) + +- Bump `pandoc` upper bound to include up to version 3.5 + (#1041, #1042, #1047) (contributions by Alexander Batischev) +- Add `renderPandocItemWithTransformM` and `pandocItemCompilerWithTransformM` + (#1020) (contribution by Tony Zorman) + ## Hakyll 4.16.2.2 (2024-07-05) - Bump `tasty-quickcheck` upper bound to 0.12 (contribution by Alexander diff --git a/hakyll.cabal b/hakyll.cabal index 84175aa2f..5a8de94fe 100644 --- a/hakyll.cabal +++ b/hakyll.cabal @@ -1,5 +1,5 @@ Name: hakyll -Version: 4.16.2.2 +Version: 4.16.3.0 Synopsis: A static website compiler library Description: @@ -254,7 +254,7 @@ Library Other-Modules: Hakyll.Web.Pandoc.Binary Build-Depends: - pandoc >= 2.11 && < 2.20 || >= 3.0 && < 3.5 + pandoc >= 2.11 && < 2.20 || >= 3.0 && < 3.6 Cpp-options: -DUSE_PANDOC @@ -321,7 +321,7 @@ Test-suite hakyll-tests Cpp-options: -DUSE_PANDOC Build-Depends: - pandoc >= 2.11 && < 2.20 || >= 3.0 && < 3.5 + pandoc >= 2.11 && < 2.20 || >= 3.0 && < 3.6 Executable hakyll-init @@ -355,4 +355,4 @@ Executable hakyll-website base >= 4.12 && < 5, directory >= 1.0 && < 1.4, filepath >= 1.0 && < 1.6, - pandoc >= 2.11 && < 2.20 || >= 3.0 && < 3.5 + pandoc >= 2.11 && < 2.20 || >= 3.0 && < 3.6 diff --git a/lib/Hakyll/Web/CompressCss.hs b/lib/Hakyll/Web/CompressCss.hs index 4aa97e0d1..5e71916af 100644 --- a/lib/Hakyll/Web/CompressCss.hs +++ b/lib/Hakyll/Web/CompressCss.hs @@ -42,14 +42,17 @@ compressSeparators = replaceAll " *[{};,>+~!] *" (take 1 . dropWhile isSpace) . replaceAll ": *" (take 1) -- not destroying pseudo selectors (#323) --- | Uses `compressCalcExpression` on all parenthesised calc expressions --- and applies `transform` to all parts outside of them +-- | Uses `compressExpression` on all parenthesised calc and +-- clamp expressions, and applies `transform` to all parts +-- outside of them handleCalcExpressions :: (String -> String) -> String -> String handleCalcExpressions transform = top transform where - top f "" = f "" - top f str | "calc(" `isPrefixOf` str = f "calc" ++ nested 0 compressCalcExpression (drop 4 str) - top f (x:xs) = top (f . (x:)) xs + top f "" = f "" + top f str | "calc(" `isPrefixOf` str = f "calc" ++ nested 0 compressExpression (drop 4 str) + -- See issue #1021 + | "clamp(" `isPrefixOf` str = f "clamp" ++ nested 0 compressExpression (drop 5 str) + top f (x:xs) = top (f . (x:)) xs -- when called with depth=0, the first character must be a '(' nested :: Int -> (String -> String) -> String -> String @@ -62,9 +65,10 @@ handleCalcExpressions transform = top transform _ -> depth ) (f . (x:)) xs --- | does not remove whitespace around + and -, which is important in calc() expressions -compressCalcExpression :: String -> String -compressCalcExpression = +-- | does not remove whitespace around + and -, which is important +-- in calc() and clamp() expressions +compressExpression :: String -> String +compressExpression = replaceAll " *[*/] *| *\\)|\\( *" (take 1 . dropWhile isSpace) -------------------------------------------------------------------------------- diff --git a/lib/Hakyll/Web/Pandoc.hs b/lib/Hakyll/Web/Pandoc.hs index c26939074..e647f0bfa 100644 --- a/lib/Hakyll/Web/Pandoc.hs +++ b/lib/Hakyll/Web/Pandoc.hs @@ -10,12 +10,14 @@ module Hakyll.Web.Pandoc , renderPandocWith , renderPandocWithTransform , renderPandocWithTransformM + , renderPandocItemWithTransformM -- * Derived compilers , pandocCompiler , pandocCompilerWith , pandocCompilerWithTransform , pandocCompilerWithTransformM + , pandocItemCompilerWithTransformM -- * Default options , defaultHakyllReaderOptions @@ -120,10 +122,12 @@ renderPandocWithTransform ropt wopt f = -------------------------------------------------------------------------------- --- | Similar to `renderPandocWithTransform`, but the Pandoc transformation is +-- | Similar to 'renderPandocWithTransform', but the Pandoc transformation is -- monadic. This is useful when you want the pandoc --- transformation to use the `Compiler` information such as routes, +-- transformation to use the 'Compiler' information such as routes, -- metadata, etc. along with your own transformations beforehand. +-- +-- @since 4.16.3.0 renderPandocWithTransformM :: ReaderOptions -> WriterOptions -> (Pandoc -> Compiler Pandoc) -> Item String @@ -132,6 +136,23 @@ renderPandocWithTransformM ropt wopt f i = writePandocWith wopt <$> (traverse f =<< readPandocWith ropt i) +-------------------------------------------------------------------------------- +-- | Like 'renderPandocWithTransformM', but work on an @'Item' 'Pandoc'@ instead +-- of just a 'Pandoc'. This allows for more seamless composition of functions +-- that require the extra information that an 'Item' provides, like +-- bibliographic transformations with +-- 'Hakyll.Web.Pandoc.Biblio.processPandocBiblio'. +-- +-- @since 4.16.3.0 +renderPandocItemWithTransformM + :: ReaderOptions -> WriterOptions + -> (Item Pandoc -> Compiler (Item Pandoc)) + -> Item String + -> Compiler (Item String) +renderPandocItemWithTransformM ropt wopt f i = + writePandocWith wopt <$> (f =<< readPandocWith ropt i) + + -------------------------------------------------------------------------------- -- | Read a page render using pandoc pandocCompiler :: Compiler (Item String) @@ -170,6 +191,20 @@ pandocCompilerWithTransformM ropt wopt f = getResourceBody >>= renderPandocWithTransformM ropt wopt f +-------------------------------------------------------------------------------- +-- | Like 'pandocCompilerWithTransformM', but work on an 'Item' 'Pandoc' +-- instead of just a 'Pandoc'. This allows for more seamless composition of +-- functions that require the extra information that an 'Item' provides, like +-- bibliographic transformations with +-- 'Hakyll.Web.Pandoc.Biblio.processPandocBiblio'. +pandocItemCompilerWithTransformM + :: ReaderOptions -> WriterOptions + -> (Item Pandoc -> Compiler (Item Pandoc)) + -> Compiler (Item String) +pandocItemCompilerWithTransformM ropt wopt f = + getResourceBody >>= renderPandocItemWithTransformM ropt wopt f + + -------------------------------------------------------------------------------- -- | The default reader options for pandoc parsing in hakyll defaultHakyllReaderOptions :: ReaderOptions diff --git a/tests/Hakyll/Core/Identifier/Tests.hs b/tests/Hakyll/Core/Identifier/Tests.hs index 8f534a2b4..658d01f42 100644 --- a/tests/Hakyll/Core/Identifier/Tests.hs +++ b/tests/Hakyll/Core/Identifier/Tests.hs @@ -6,14 +6,16 @@ module Hakyll.Core.Identifier.Tests -------------------------------------------------------------------------------- +import qualified Test.QuickCheck as Q import Test.Tasty (TestTree, testGroup) import Test.Tasty.HUnit ((@=?)) +import Test.Tasty.QuickCheck (testProperty) -------------------------------------------------------------------------------- import Hakyll.Core.Identifier import Hakyll.Core.Identifier.Pattern -import System.FilePath (()) +import System.FilePath ((), isValid, equalFilePath, pathSeparators) import TestSuite.Util @@ -22,6 +24,7 @@ tests :: TestTree tests = testGroup "Hakyll.Core.Identifier.Tests" $ concat [ captureTests , matchesTests + , [ testProperty "toFilePath . fromFilePath" filepathConversionProp ] ] @@ -59,3 +62,16 @@ matchesTests = fromAssertions "matches" , True @=? matches ("foo" .||. "bar") "bar" , False @=? matches ("bar" .&&. hasNoVersion) (setVersion (Just "xz") "bar") ] + + +-------------------------------------------------------------------------------- +-- Ensure that `fromFilePath` and `toFilePath` are inverses of each other (#791) +filepathConversionProp :: Q.Property +filepathConversionProp + = Q.forAll genFilePath + $ \fp -> toFilePath (fromFilePath fp) `equalFilePath` fp + where + genFilePath + = Q.listOf1 (Q.elements $ ['a'..'z'] <> pathSeparators) + `Q.suchThat` + isValid \ No newline at end of file diff --git a/tests/Hakyll/Web/CompressCss/Tests.hs b/tests/Hakyll/Web/CompressCss/Tests.hs index ae4aba023..fcc5cde2a 100644 --- a/tests/Hakyll/Web/CompressCss/Tests.hs +++ b/tests/Hakyll/Web/CompressCss/Tests.hs @@ -43,6 +43,8 @@ tests = testGroup "Hakyll.Web.CompressCss.Tests" $ concat , "a!b" @=? compressCss "a ! b" -- compress calc() , "calc(1px + 100%/(5 + 3) - (3px + 2px)*5)" @=? compressCss "calc( 1px + 100% / ( 5 + 3) - calc( 3px + 2px ) * 5 )" + -- compress clamp() (issue #1021) + , "clamp(2.25rem, 2vw + 1.5rem, 3.25rem)" @=? compressCss "clamp(2.25rem, 2vw + 1.5rem, 3.25rem)" -- compress whitespace even after this curly brace , "}" @=? compressCss "; } " -- but do not compress separators inside string tokens diff --git a/web/examples.markdown b/web/examples.markdown index 8439b760a..3eefa0361 100644 --- a/web/examples.markdown +++ b/web/examples.markdown @@ -144,3 +144,5 @@ directly with the default Hakyll site. [source](https://github.com/michaelxavier/michaelxavier.net) - , [source](https://github.com/slotThe/slotThe.github.io) +- , + [source](https://github.com/Sahel13/Sahel13.github.io)