diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2011-11-21 20:27:35 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2011-11-21 20:27:35 +0100 |
commit | d3140f397c2cdf3be193380d1f9bea003817a49e (patch) | |
tree | de534fcc655d04465e2c030e22b50c0117c8bb6e /src/Hakyll/Web | |
parent | 2ff210019fec158c178ae6d8f28b7996ecf566cd (diff) | |
download | hakyll-d3140f397c2cdf3be193380d1f9bea003817a49e.tar.gz |
Add a Pandoc.Biblio module
Diffstat (limited to 'src/Hakyll/Web')
-rw-r--r-- | src/Hakyll/Web/Pandoc/Biblio.hs | 57 |
1 files changed, 57 insertions, 0 deletions
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 |