@@ -0,0 +1,57 @@
1+-- | Wraps pandocs bibiliography handling
2+{-# LANGUAGE Arrows, DeriveDataTypeable, GeneralizedNewtypeDeriving #-}
3+module Hakyll.Web.Pandoc.Biblio
4+ ( CSL
5+ , cslCompiler
6+ , References (..)
7+ , referencesCompiler
8+ , processBiblioCompiler
9+ ) where
10+
11+import Control.Applicative ((<$>))
12+import Control.Arrow (arr, returnA)
13+import Data.Typeable (Typeable)
14+
15+import Data.Binary (Binary (..))
16+import Text.Pandoc (Pandoc)
17+import Text.Pandoc.Biblio (processBiblio)
18+import qualified Text.CSL as CSL
19+
20+import Hakyll.Core.Compiler
21+import Hakyll.Core.Identifier
22+import Hakyll.Core.Resource
23+import Hakyll.Core.Writable
24+import Hakyll.Web.Page
25+
26+newtype CSL = CSL FilePath
27+ deriving (Binary, Show, Typeable, Writable)
28+
29+cslCompiler :: Compiler Resource CSL
30+cslCompiler = arr (CSL . unResource)
31+
32+newtype References = References [CSL.Reference]
33+ deriving (Show, Typeable)
34+
35+instance Binary References where
36+ -- Ugly.
37+ get = References . read <$> get
38+ put (References rs) = put $ show rs
39+
40+instance Writable References where
41+ write _ _ = return ()
42+
43+referencesCompiler :: Compiler Resource References
44+referencesCompiler = unsafeCompiler $
45+ fmap References . CSL.readBiblioFile . unResource
46+
47+processBiblioCompiler :: Identifier CSL
48+ -> Identifier References
49+ -> Compiler (Page Pandoc) (Page Pandoc)
50+processBiblioCompiler csl refs = proc page -> do
51+ let body = pageBody page
52+ CSL csl' <- require_ csl -< ()
53+ References refs' <- require_ refs -< ()
54+ body' <- unsafeCompiler (tuc processBiblio) -< (csl', refs', body)
55+ returnA -< page {pageBody = body'}
56+ where
57+ tuc f (x, y, z) = f x y z