hakyll 3.2.0.10 → 3.2.1.0
raw patch · 4 files changed
+90/−5 lines, 4 filesdep +citeproc-hs
Dependencies added: citeproc-hs
Files
- hakyll.cabal +3/−1
- src/Hakyll.hs +2/−0
- src/Hakyll/Web/Pandoc.hs +12/−4
- src/Hakyll/Web/Pandoc/Biblio.hs +73/−0
hakyll.cabal view
@@ -1,5 +1,5 @@ Name: hakyll-Version: 3.2.0.10+Version: 3.2.1.0 Synopsis: A static website compiler library Description:@@ -63,6 +63,7 @@ binary >= 0.5 && < 1.0, blaze-html >= 0.4 && < 0.6, bytestring >= 0.9 && < 1.0,+ citeproc-hs >= 0.3.2 && < 0.4, containers >= 0.3 && < 1.0, cryptohash >= 0.7 && < 0.8, directory >= 1.0 && < 1.3,@@ -114,6 +115,7 @@ Hakyll.Web.Page.Metadata Hakyll.Web.Page.Read Hakyll.Web.Pandoc+ Hakyll.Web.Pandoc.Biblio Hakyll.Web.Pandoc.FileType Hakyll.Web.Tags Hakyll.Web.Template
src/Hakyll.hs view
@@ -25,6 +25,7 @@ , module Hakyll.Web.Page.Metadata , module Hakyll.Web.Page.Read , module Hakyll.Web.Pandoc+ , module Hakyll.Web.Pandoc.Biblio , module Hakyll.Web.Pandoc.FileType , module Hakyll.Web.Urls , module Hakyll.Web.Urls.Relativize@@ -57,6 +58,7 @@ import Hakyll.Web.Page.Metadata import Hakyll.Web.Page.Read import Hakyll.Web.Pandoc+import Hakyll.Web.Pandoc.Biblio import Hakyll.Web.Pandoc.FileType import Hakyll.Web.Urls import Hakyll.Web.Urls.Relativize
src/Hakyll/Web/Pandoc.hs view
@@ -10,6 +10,7 @@ -- * Functions working on pages/compilers , pageReadPandoc , pageReadPandocWith+ , pageReadPandocWithA , pageRenderPandoc , pageRenderPandocWith @@ -20,7 +21,7 @@ import Prelude hiding (id) import Control.Applicative ((<$>))-import Control.Arrow ((>>^), (&&&))+import Control.Arrow ((>>>), (>>^), (&&&), (***)) import Control.Category (id) import Data.Maybe (fromMaybe) @@ -28,6 +29,7 @@ import Hakyll.Core.Compiler import Hakyll.Core.Identifier+import Hakyll.Core.Util.Arrow import Hakyll.Web.Pandoc.FileType import Hakyll.Web.Page.Internal @@ -78,10 +80,16 @@ -- | Read the resource using pandoc -- pageReadPandocWith :: ParserState -> Compiler (Page String) (Page Pandoc)-pageReadPandocWith state =- id &&& getIdentifier &&& getFileType >>^ pageReadPandocWith'+pageReadPandocWith state = constA state &&& id >>> pageReadPandocWithA++-- | Read the resource using pandoc. This is a (rarely needed) variant, which+-- comes in very useful when the parser state is the result of some arrow.+--+pageReadPandocWithA :: Compiler (ParserState, Page String) (Page Pandoc)+pageReadPandocWithA =+ id *** id &&& getIdentifier &&& getFileType >>^ pageReadPandocWithA' where- pageReadPandocWith' (p, (i, t)) = readPandocWith state t (Just i) <$> p+ pageReadPandocWithA' (s, (p, (i, t))) = readPandocWith s t (Just i) <$> p -- | Render the resource using pandoc --
+ src/Hakyll/Web/Pandoc/Biblio.hs view
@@ -0,0 +1,73 @@+-- | Wraps pandocs bibiliography handling+--+-- In order to add a bibliography, you will need a bibliography file (e.g.+-- @.bib@) and a CSL file (@.csl@). Both need to be compiled with their+-- respective compilers ('biblioCompiler' and 'cslCompiler'). Then, you can+-- refer to these files when you use 'pageReadPandocBiblio'. This function also+-- takes a parser state for completeness -- you can use+-- 'defaultHakyllParserState' if you're unsure.+--+{-# LANGUAGE Arrows, DeriveDataTypeable, GeneralizedNewtypeDeriving #-}+module Hakyll.Web.Pandoc.Biblio+ ( CSL+ , cslCompiler+ , Biblio (..)+ , biblioCompiler+ , pageReadPandocBiblio+ ) where++import Control.Applicative ((<$>))+import Control.Arrow (arr, returnA)+import Data.Typeable (Typeable)++import Data.Binary (Binary (..))+import Text.Pandoc (Pandoc, ParserState (..))+import Text.Pandoc.Biblio (processBiblio)+import qualified Text.CSL as CSL++import Hakyll.Core.Compiler+import Hakyll.Core.Identifier+import Hakyll.Core.Resource+import Hakyll.Core.Writable+import Hakyll.Web.Page+import Hakyll.Web.Pandoc++newtype CSL = CSL FilePath+ deriving (Binary, Show, Typeable, Writable)++cslCompiler :: Compiler Resource CSL+cslCompiler = arr (CSL . unResource)++newtype Biblio = Biblio [CSL.Reference]+ deriving (Show, Typeable)++instance Binary Biblio where+ -- Ugly.+ get = Biblio . read <$> get+ put (Biblio rs) = put $ show rs++instance Writable Biblio where+ write _ _ = return ()++biblioCompiler :: Compiler Resource Biblio+biblioCompiler = unsafeCompiler $+ fmap Biblio . CSL.readBiblioFile . unResource++pageReadPandocBiblio :: ParserState+ -> Identifier CSL+ -> Identifier Biblio+ -> Compiler (Page String) (Page Pandoc)+pageReadPandocBiblio state csl refs = proc page -> do+ CSL csl' <- require_ csl -< ()+ Biblio refs' <- require_ refs -< ()+ -- We need to know the citation keys, add then *before* actually parsing the+ -- actual page. If we don't do this, pandoc won't even consider them+ -- citations!+ let cits = map CSL.refId refs'+ state' = state {stateCitations = stateCitations state ++ cits}+ pandocPage <- pageReadPandocWithA -< (state', page)+ let pandoc = pageBody pandocPage+ pandoc' <- unsafeCompiler (tuc processBiblio) -< (csl', refs', pandoc)+ returnA -< pandocPage {pageBody = pandoc'}+ where+ tuc f (x, y, z) = f x y z