Add a Pandoc.Biblio module
This commit is contained in:
parent
2ff210019f
commit
d3140f397c
2 changed files with 59 additions and 0 deletions
|
@ -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
|
||||
|
|
57
src/Hakyll/Web/Pandoc/Biblio.hs
Normal file
57
src/Hakyll/Web/Pandoc/Biblio.hs
Normal file
|
@ -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
|
Loading…
Reference in a new issue