diff options
-rw-r--r-- | hakyll.cabal | 2 | ||||
-rw-r--r-- | src/Hakyll/Web/Pandoc/Biblio.hs | 57 |
2 files changed, 59 insertions, 0 deletions
diff --git a/hakyll.cabal b/hakyll.cabal index ced8022..f18ddb7 100644 --- a/hakyll.cabal +++ b/hakyll.cabal @@ -63,6 +63,7 @@ Library 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 @@ Library 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 diff --git a/src/Hakyll/Web/Pandoc/Biblio.hs b/src/Hakyll/Web/Pandoc/Biblio.hs new file mode 100644 index 0000000..6cc9f83 --- /dev/null +++ b/src/Hakyll/Web/Pandoc/Biblio.hs @@ -0,0 +1,57 @@ +-- | Wraps pandocs bibiliography handling +{-# LANGUAGE Arrows, DeriveDataTypeable, GeneralizedNewtypeDeriving #-} +module Hakyll.Web.Pandoc.Biblio + ( CSL + , cslCompiler + , References (..) + , referencesCompiler + , processBiblioCompiler + ) where + +import Control.Applicative ((<$>)) +import Control.Arrow (arr, returnA) +import Data.Typeable (Typeable) + +import Data.Binary (Binary (..)) +import Text.Pandoc (Pandoc) +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 + +newtype CSL = CSL FilePath + deriving (Binary, Show, Typeable, Writable) + +cslCompiler :: Compiler Resource CSL +cslCompiler = arr (CSL . unResource) + +newtype References = References [CSL.Reference] + deriving (Show, Typeable) + +instance Binary References where + -- Ugly. + get = References . read <$> get + put (References rs) = put $ show rs + +instance Writable References where + write _ _ = return () + +referencesCompiler :: Compiler Resource References +referencesCompiler = unsafeCompiler $ + fmap References . CSL.readBiblioFile . unResource + +processBiblioCompiler :: Identifier CSL + -> Identifier References + -> Compiler (Page Pandoc) (Page Pandoc) +processBiblioCompiler csl refs = proc page -> do + let body = pageBody page + CSL csl' <- require_ csl -< () + References refs' <- require_ refs -< () + body' <- unsafeCompiler (tuc processBiblio) -< (csl', refs', body) + returnA -< page {pageBody = body'} + where + tuc f (x, y, z) = f x y z |