Skip to content

Commit

Permalink
Merge branch 'jaspervdj:master' into hlint
Browse files Browse the repository at this point in the history
  • Loading branch information
chungyc authored Oct 28, 2024
2 parents 55e1205 + e0c19ef commit 3c43bea
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 15 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions hakyll.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: hakyll
Version: 4.16.2.2
Version: 4.16.3.0

Synopsis: A static website compiler library
Description:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
20 changes: 12 additions & 8 deletions lib/Hakyll/Web/CompressCss.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

--------------------------------------------------------------------------------
Expand Down
39 changes: 37 additions & 2 deletions lib/Hakyll/Web/Pandoc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ module Hakyll.Web.Pandoc
, renderPandocWith
, renderPandocWithTransform
, renderPandocWithTransformM
, renderPandocItemWithTransformM

-- * Derived compilers
, pandocCompiler
, pandocCompilerWith
, pandocCompilerWithTransform
, pandocCompilerWithTransformM
, pandocItemCompilerWithTransformM

-- * Default options
, defaultHakyllReaderOptions
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion tests/Hakyll/Core/Identifier/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -22,6 +24,7 @@ tests :: TestTree
tests = testGroup "Hakyll.Core.Identifier.Tests" $ concat
[ captureTests
, matchesTests
, [ testProperty "toFilePath . fromFilePath" filepathConversionProp ]
]


Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions tests/Hakyll/Web/CompressCss/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions web/examples.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,5 @@ directly with the default Hakyll site.
[source](https://github.com/michaelxavier/michaelxavier.net)
- <https://tony-zorman.com/>,
[source](https://github.com/slotThe/slotThe.github.io)
- <https://sahel13.github.io/>,
[source](https://github.com/Sahel13/Sahel13.github.io)

0 comments on commit 3c43bea

Please sign in to comment.