summaryrefslogtreecommitdiff
path: root/src/Hakyll/Web/Pandoc
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2012-11-18 21:56:52 +0100
committerJasper Van der Jeugt <m@jaspervdj.be>2012-11-18 21:56:52 +0100
commit877cb21d1630d32c6e40eb7c6f0ecc7e1da2bd52 (patch)
tree57ce11325adbbb7502086450dd1d1a9f1e81b8f2 /src/Hakyll/Web/Pandoc
parent1347b0fa6cdd98986f927368e76e849068f69e1a (diff)
downloadhakyll-877cb21d1630d32c6e40eb7c6f0ecc7e1da2bd52.tar.gz
Add Item abstraction
Diffstat (limited to 'src/Hakyll/Web/Pandoc')
-rw-r--r--src/Hakyll/Web/Pandoc/Biblio.hs57
-rw-r--r--src/Hakyll/Web/Pandoc/FileType.hs9
2 files changed, 41 insertions, 25 deletions
diff --git a/src/Hakyll/Web/Pandoc/Biblio.hs b/src/Hakyll/Web/Pandoc/Biblio.hs
index ca8d10e..8c284a0 100644
--- a/src/Hakyll/Web/Pandoc/Biblio.hs
+++ b/src/Hakyll/Web/Pandoc/Biblio.hs
@@ -15,7 +15,7 @@ module Hakyll.Web.Pandoc.Biblio
, cslCompiler
, Biblio (..)
, biblioCompiler
- , pageReadPandocBiblio
+ , readPandocBiblio
) where
@@ -31,19 +31,31 @@ import Text.Pandoc.Biblio (processBiblio)
--------------------------------------------------------------------------------
import Hakyll.Core.Compiler
import Hakyll.Core.Identifier
+import Hakyll.Core.Item
import Hakyll.Core.Writable
-import Hakyll.Web.Page
import Hakyll.Web.Pandoc
--------------------------------------------------------------------------------
-newtype CSL = CSL FilePath
- deriving (Binary, Show, Typeable, Writable)
+data CSL = CSL
+ deriving (Show, Typeable)
+
+
+--------------------------------------------------------------------------------
+instance Binary CSL where
+ put CSL = return ()
+ get = return CSL
+
+
+--------------------------------------------------------------------------------
+instance Writable CSL where
+ -- Shouldn't be written.
+ write _ _ = return ()
--------------------------------------------------------------------------------
-cslCompiler :: Compiler CSL
-cslCompiler = CSL . toFilePath <$> getIdentifier
+cslCompiler :: Compiler (Item CSL)
+cslCompiler = makeItem CSL
--------------------------------------------------------------------------------
@@ -57,29 +69,34 @@ instance Binary Biblio where
get = Biblio . read <$> get
put (Biblio rs) = put $ show rs
+
+--------------------------------------------------------------------------------
instance Writable Biblio where
+ -- Shouldn't be written.
write _ _ = return ()
--------------------------------------------------------------------------------
-biblioCompiler :: Compiler Biblio
+biblioCompiler :: Compiler (Item Biblio)
biblioCompiler = do
- filePath <- toFilePath <$> getIdentifier
- unsafeCompiler $ Biblio <$> CSL.readBiblioFile filePath
+ filePath <- toFilePath <$> getUnderlying
+ makeItem =<< unsafeCompiler (Biblio <$> CSL.readBiblioFile filePath)
--------------------------------------------------------------------------------
-pageReadPandocBiblio :: ParserState
- -> CSL
- -> Biblio
- -> Page
- -> Compiler Pandoc
-pageReadPandocBiblio state (CSL csl) (Biblio refs) page = do
+readPandocBiblio :: ParserState
+ -> Item CSL
+ -> Item Biblio
+ -> (Item String)
+ -> Compiler (Item Pandoc)
+readPandocBiblio state csl biblio item = do
-- We need to know the citation keys, add then *before* actually parsing the
-- actual page. If we don't do this, pandoc won't even consider them
-- citations!
- let cits = map CSL.refId refs
- state' = state {stateCitations = stateCitations state ++ cits}
- pandoc <- pageReadPandocWith state' page
- pandoc' <- unsafeCompiler $ processBiblio csl Nothing refs pandoc
- return pandoc'
+ let Biblio refs = itemBody biblio
+ cits = map CSL.refId refs
+ state' = state {stateCitations = stateCitations state ++ cits}
+ pandoc = itemBody $ readPandocWith state' item
+ cslPath = toFilePath $ itemIdentifier csl
+ pandoc' <- unsafeCompiler $ processBiblio cslPath Nothing refs pandoc
+ return $ fmap (const pandoc') item
diff --git a/src/Hakyll/Web/Pandoc/FileType.hs b/src/Hakyll/Web/Pandoc/FileType.hs
index 2d28edd..1ae4c10 100644
--- a/src/Hakyll/Web/Pandoc/FileType.hs
+++ b/src/Hakyll/Web/Pandoc/FileType.hs
@@ -3,18 +3,17 @@
module Hakyll.Web.Pandoc.FileType
( FileType (..)
, fileType
- , getFileType
+ , itemFileType
) where
--------------------------------------------------------------------------------
-import Control.Applicative ((<$>))
import System.FilePath (takeExtension)
--------------------------------------------------------------------------------
-import Hakyll.Core.Compiler
import Hakyll.Core.Identifier
+import Hakyll.Core.Item
--------------------------------------------------------------------------------
@@ -62,5 +61,5 @@ fileType = fileType' . takeExtension
--------------------------------------------------------------------------------
-- | Get the file type for the current file
-getFileType :: Compiler FileType
-getFileType = fileType . toFilePath <$> getIdentifier
+itemFileType :: Item a -> FileType
+itemFileType = fileType . toFilePath . itemIdentifier