diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2012-11-10 18:11:46 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2012-11-10 18:11:46 +0100 |
commit | 141e761ce11d4d4ae9e9b86201249dbd549e2924 (patch) | |
tree | 0d0ba398331bceb9326c58392680fb81361fb6c3 /src/Hakyll/Web/Pandoc | |
parent | 260e4e2e8936f756d2f3a2e6e788f05ca28e4324 (diff) | |
download | hakyll-141e761ce11d4d4ae9e9b86201249dbd549e2924.tar.gz |
Deprecate things, basics now work
Diffstat (limited to 'src/Hakyll/Web/Pandoc')
-rw-r--r-- | src/Hakyll/Web/Pandoc/Biblio.hs | 26 | ||||
-rw-r--r-- | src/Hakyll/Web/Pandoc/FileType.hs | 23 |
2 files changed, 35 insertions, 14 deletions
diff --git a/src/Hakyll/Web/Pandoc/Biblio.hs b/src/Hakyll/Web/Pandoc/Biblio.hs index 64a702b..699ba31 100644 --- a/src/Hakyll/Web/Pandoc/Biblio.hs +++ b/src/Hakyll/Web/Pandoc/Biblio.hs @@ -1,3 +1,4 @@ +-------------------------------------------------------------------------------- -- | Wraps pandocs bibiliography handling -- -- In order to add a bibliography, you will need a bibliography file (e.g. @@ -6,7 +7,6 @@ -- refer to these files when you use 'pageReadPandocBiblio'. This function also -- takes a parser state for completeness -- you can use -- 'defaultHakyllParserState' if you're unsure. --- {-# LANGUAGE Arrows, DeriveDataTypeable, GeneralizedNewtypeDeriving #-} module Hakyll.Web.Pandoc.Biblio ( CSL @@ -16,30 +16,41 @@ module Hakyll.Web.Pandoc.Biblio , pageReadPandocBiblio ) where + +-------------------------------------------------------------------------------- import Control.Applicative ((<$>)) import Control.Arrow (arr, returnA, (>>>)) import Data.Typeable (Typeable) - import Data.Binary (Binary (..)) import Text.Pandoc (Pandoc, ParserState (..)) import Text.Pandoc.Biblio (processBiblio) import qualified Text.CSL as CSL + +-------------------------------------------------------------------------------- import Hakyll.Core.Compiler import Hakyll.Core.Identifier import Hakyll.Core.Writable import Hakyll.Web.Page import Hakyll.Web.Pandoc + +-------------------------------------------------------------------------------- newtype CSL = CSL FilePath deriving (Binary, Show, Typeable, Writable) + +-------------------------------------------------------------------------------- cslCompiler :: Compiler () CSL cslCompiler = getIdentifier >>> arr (CSL . toFilePath) + +-------------------------------------------------------------------------------- newtype Biblio = Biblio [CSL.Reference] deriving (Show, Typeable) + +-------------------------------------------------------------------------------- instance Binary Biblio where -- Ugly. get = Biblio . read <$> get @@ -48,14 +59,18 @@ instance Binary Biblio where instance Writable Biblio where write _ _ = return () + +-------------------------------------------------------------------------------- biblioCompiler :: Compiler () Biblio biblioCompiler = getIdentifier >>> arr toFilePath >>> unsafeCompiler CSL.readBiblioFile >>> arr Biblio + +-------------------------------------------------------------------------------- pageReadPandocBiblio :: ParserState -> Identifier CSL -> Identifier Biblio - -> Compiler (Page String) (Page Pandoc) + -> Compiler Page Pandoc pageReadPandocBiblio state csl refs = proc page -> do CSL csl' <- require_ csl -< () Biblio refs' <- require_ refs -< () @@ -64,9 +79,8 @@ pageReadPandocBiblio state csl refs = proc page -> do -- citations! let cits = map CSL.refId refs' state' = state {stateCitations = stateCitations state ++ cits} - pandocPage <- pageReadPandocWithA -< (state', page) - let pandoc = pageBody pandocPage + pandoc <- pageReadPandocWithA -< (state', page) pandoc' <- unsafeCompiler processBiblio' -< (csl', refs', pandoc) - returnA -< pandocPage {pageBody = pandoc'} + returnA -< pandoc' where processBiblio' (c, r, p) = processBiblio c Nothing r p diff --git a/src/Hakyll/Web/Pandoc/FileType.hs b/src/Hakyll/Web/Pandoc/FileType.hs index bde0e4e..db24da7 100644 --- a/src/Hakyll/Web/Pandoc/FileType.hs +++ b/src/Hakyll/Web/Pandoc/FileType.hs @@ -1,20 +1,25 @@ +-------------------------------------------------------------------------------- -- | A module dealing with pandoc file extensions and associated file types --- module Hakyll.Web.Pandoc.FileType ( FileType (..) , fileType , getFileType ) where -import System.FilePath (takeExtension) -import Control.Arrow ((>>^)) -import Hakyll.Core.Identifier -import Hakyll.Core.Compiler +-------------------------------------------------------------------------------- +import Control.Arrow ((>>^)) +import System.FilePath (takeExtension) + +-------------------------------------------------------------------------------- +import Hakyll.Core.Compiler +import Hakyll.Core.Identifier + + +-------------------------------------------------------------------------------- -- | Datatype to represent the different file types Hakyll can deal with by -- default --- data FileType = Binary | Css @@ -28,8 +33,9 @@ data FileType | Textile deriving (Eq, Ord, Show, Read) + +-------------------------------------------------------------------------------- -- | Get the file type for a certain file. The type is determined by extension. --- fileType :: FilePath -> FileType fileType = fileType' . takeExtension where @@ -53,7 +59,8 @@ fileType = fileType' . takeExtension fileType' ".txt" = PlainText fileType' _ = Binary -- Treat unknown files as binary + +-------------------------------------------------------------------------------- -- | Get the file type for the current file --- getFileType :: Compiler a FileType getFileType = getIdentifier >>^ fileType . toFilePath |