on master help sign in
Add a Pandoc.Biblio module
commitd3140f397c2cdf3be193380d1f9bea003817a49e authorJasper Van der Jeugt <m@jaspervdj.be> dateMon 21 Nov 2011, 20:27 (15 years ago) parent2ff2100
2 files changed+59
hakyll.cabal+2 src/Hakyll/Web/Pandoc/Biblio.hs+57
hakyll.cabal+2
@@ -63,6 +63,7 @@ Library
6363 binary >= 0.5 && < 1.0,
6464 blaze-html >= 0.4 && < 0.6,
6565 bytestring >= 0.9 && < 1.0,
66+ citeproc-hs >= 0.3.2 && < 0.4,
6667 containers >= 0.3 && < 1.0,
6768 cryptohash >= 0.7 && < 0.8,
6869 directory >= 1.0 && < 1.3,
@@ -114,6 +115,7 @@ Library
114115 Hakyll.Web.Page.Metadata
115116 Hakyll.Web.Page.Read
116117 Hakyll.Web.Pandoc
118+ Hakyll.Web.Pandoc.Biblio
117119 Hakyll.Web.Pandoc.FileType
118120 Hakyll.Web.Tags
119121 Hakyll.Web.Template
src/Hakyll/Web/Pandoc/Biblio.hsnew file+57
@@ -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