hakyll 4.16.4.0 → 4.16.5.0
raw patch · 3 files changed
+77/−17 lines, 3 filesdep +pandoc-typesdep ~template-haskellPVP ok
version bump matches the API change (PVP)
Dependencies added: pandoc-types
Dependency ranges changed: template-haskell
API changes (from Hackage documentation)
Files
- CHANGELOG.md +8/−2
- hakyll.cabal +9/−6
- lib/Hakyll/Web/Pandoc/Biblio.hs +60/−9
CHANGELOG.md view
@@ -4,9 +4,15 @@ # Releases +## Hakyll 4.16.5.0 (2025-01-11)++- GHC 9.12 compatibility: bump `template-haskell` upper bound to include 2.23+- Add support for `nocite` metadata field to `processPandocBiblio` and+ `processPandocBiblios` (#1058) (contribution by Tony Zorman)+ ## Hakyll 4.16.4.0 (2024-12-08) -- Fixed an issue where compressing CSS with `clamp` expressions would +- Fixed an issue where compressing CSS with `clamp` expressions would result in invalid CSS (#1021) (contribution by Laurent P. René de Cotret) - Added `boolFieldM` (#1044) (contribution by 0xd34df00d) - Run HLint as part of GitHub Actions (#1045) (contribution by Yoo Chung)@@ -114,7 +120,7 @@ Alexander Batischev) - Allow `pandoc` 3.0. Note that the behavior of Hakyll's `readPandocBiblios` and `readPandocBiblio` is different whether pandoc 2 or 3 is installed- (contribution by Laurent P. René de Cotret) + (contribution by Laurent P. René de Cotret) - Bump `mtl` upper bound to allow 2.3 (contribution by Alexander Batischev) - Bump `pandoc` upper bound to allow 3.1 (contribution by Laurent P. René de Cotret)
hakyll.cabal view
@@ -1,5 +1,5 @@ Name: hakyll-Version: 4.16.4.0+Version: 4.16.5.0 Synopsis: A static website compiler library Description:@@ -204,12 +204,12 @@ optparse-applicative >= 0.12 && < 0.19, parsec >= 3.0 && < 3.2, process >= 1.6 && < 1.7,- random >= 1.0 && < 1.3,+ random >= 1.0 && < 1.4, regex-tdfa >= 1.1 && < 1.4, resourcet >= 1.1 && < 1.4, scientific >= 0.3.4 && < 0.4, tagsoup >= 0.13.1 && < 0.15,- template-haskell >= 2.14 && < 2.23,+ template-haskell >= 2.14 && < 2.24, text >= 0.11 && < 1.3 || >= 2.0 && < 2.2, time >= 1.8 && < 1.15, time-locale-compat >= 0.1 && < 0.2,@@ -252,7 +252,8 @@ Other-Modules: Hakyll.Web.Pandoc.Binary Build-Depends:- pandoc >= 2.11 && < 2.20 || >= 3.0 && < 3.7+ pandoc >= 2.11 && < 2.20 || >= 3.0 && < 3.7,+ pandoc-types >= 1.22 && < 1.24 Cpp-options: -DUSE_PANDOC @@ -317,7 +318,8 @@ Cpp-options: -DUSE_PANDOC Build-Depends:- pandoc >= 2.11 && < 2.20 || >= 3.0 && < 3.7+ pandoc >= 2.11 && < 2.20 || >= 3.0 && < 3.7,+ pandoc-types >= 1.22 && < 1.24 Executable hakyll-init@@ -351,4 +353,5 @@ base >= 4.12 && < 5, directory >= 1.0 && < 1.4, filepath >= 1.0 && < 1.6,- pandoc >= 2.11 && < 2.20 || >= 3.0 && < 3.7+ pandoc >= 2.11 && < 2.20 || >= 3.0 && < 3.7,+ pandoc-types >= 1.22 && < 1.24
lib/Hakyll/Web/Pandoc/Biblio.hs view
@@ -15,6 +15,7 @@ {-# LANGUAGE Arrows #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} module Hakyll.Web.Pandoc.Biblio ( CSL (..)@@ -44,13 +45,16 @@ import Hakyll.Core.Identifier import Hakyll.Core.Identifier.Pattern (fromGlob) import Hakyll.Core.Item+import Hakyll.Core.Metadata (getMetadataField) import Hakyll.Core.Writable import Hakyll.Web.Pandoc import Text.Pandoc (Extension (..), Pandoc,- ReaderOptions (..),+ PandocPure, ReaderOptions (..), enableExtension) import qualified Text.Pandoc as Pandoc+import Text.Pandoc.Builder (setMeta) import qualified Text.Pandoc.Citeproc as Pandoc (processCitations)+import Text.Pandoc.Walk (Walkable (query)) import System.FilePath (addExtension, takeExtension) @@ -106,17 +110,47 @@ --------------------------------------------------------------------------------++-- | Process a bibliography file with the given style.+--+-- This function supports pandoc's+-- <https://pandoc.org/chunkedhtml-demo/9.6-including-uncited-items-in-the-bibliography.html nocite>+-- functionality when there is a @nocite@ metadata field present.+--+-- ==== __Example__+--+-- In your main function, first compile the respective files:+--+-- > main = hakyll $ do+-- > …+-- > match "style.csl" $ compile cslCompiler+-- > match "bib.bib" $ compile biblioCompiler+--+-- Then, create a function like the following:+--+-- > processBib :: Item Pandoc -> Compiler (Item Pandoc)+-- > processBib pandoc = do+-- > csl <- load @CSL "bib/style.csl"+-- > bib <- load @Biblio "bib/bibliography.bib"+-- > processPandocBiblio csl bib pandoc+--+-- Now, feed this function to your pandoc compiler:+--+-- > myCompiler :: Compiler (Item String)+-- > myCompiler = pandocItemCompilerWithTransformM myReader myWriter processBib processPandocBiblio :: Item CSL -> Item Biblio -> (Item Pandoc) -> Compiler (Item Pandoc) processPandocBiblio csl biblio = processPandocBiblios csl [biblio] +-- | Like 'processPandocBiblio', which see, but support multiple bibliography+-- files. processPandocBiblios :: Item CSL -> [Item Biblio] -> (Item Pandoc) -> Compiler (Item Pandoc)-processPandocBiblios csl biblios item = do+processPandocBiblios csl biblios item' = do -- It's not straightforward to use the Pandoc API as of 2.11 to deal with -- citations, since it doesn't export many things in 'Text.Pandoc.Citeproc'. -- The 'citeproc' package is also hard to use.@@ -126,6 +160,12 @@ -- -- So we load the CSL and Biblio files and pass them to Pandoc using the -- ersatz filesystem.++ -- Honour nocite metadata fields+ item <- getUnderlying >>= (`getMetadataField` "nocite") >>= \case+ Nothing -> pure item'+ Just x -> withItemBody (pure . setMeta "nocite" x) item'+ let Pandoc.Pandoc (Pandoc.Meta meta) blocks = itemBody item cslFile = Pandoc.FileInfo zeroTime . unCSL $ itemBody csl bibFiles = zipWith (\x y ->@@ -148,19 +188,30 @@ Map.insert "bibliography" (Pandoc.MetaList $ map (Pandoc.MetaString . T.pack . fst) bibFiles) $ meta- errOrPandoc = Pandoc.runPure $ do- Pandoc.modifyPureState addBiblioFiles- Pandoc.processCitations $ Pandoc.Pandoc biblioMeta blocks - pandoc <- case errOrPandoc of- Left e -> compilerThrow ["Error during processCitations: " ++ show e]- Right x -> return x-+ pandoc <- do+ let p = Pandoc.Pandoc biblioMeta blocks+ p' <- case Pandoc.lookupMeta "nocite" biblioMeta of+ Just (Pandoc.MetaString nocite) -> do+ Pandoc.Pandoc _ b <- runPandoc $+ Pandoc.readMarkdown defaultHakyllReaderOptions nocite+ let nocites = Pandoc.MetaInlines . flip query b $ \case+ c@Pandoc.Cite{} -> [c]+ _ -> []+ return $ setMeta "nocite" nocites p+ _ -> return p+ runPandoc $ do+ Pandoc.modifyPureState addBiblioFiles+ Pandoc.processCitations p' return $ fmap (const pandoc) item where zeroTime = Time.UTCTime (toEnum 0) 0 + runPandoc :: PandocPure a -> Compiler a+ runPandoc with = case Pandoc.runPure with of+ Left e -> compilerThrow ["Error during processCitations: " ++ show e]+ Right x -> pure x -------------------------------------------------------------------------------- -- | Compiles a markdown file via Pandoc. Requires the .csl and .bib files to be known to the compiler via match statements.