summaryrefslogtreecommitdiff
path: root/src/Hakyll/Web
diff options
context:
space:
mode:
Diffstat (limited to 'src/Hakyll/Web')
-rw-r--r--src/Hakyll/Web/Html.hs2
-rw-r--r--src/Hakyll/Web/Pandoc/Biblio.hs15
-rw-r--r--src/Hakyll/Web/Template/Context.hs26
-rw-r--r--src/Hakyll/Web/Template/Read.hs2
4 files changed, 32 insertions, 13 deletions
diff --git a/src/Hakyll/Web/Html.hs b/src/Hakyll/Web/Html.hs
index 3a0aa3b..f5a7ccc 100644
--- a/src/Hakyll/Web/Html.hs
+++ b/src/Hakyll/Web/Html.hs
@@ -25,7 +25,7 @@ import Data.Char (digitToInt, intToDigit,
isDigit, toLower)
import Data.List (isPrefixOf)
import qualified Data.Set as S
-import System.FilePath (joinPath, splitPath,
+import System.FilePath.Posix (joinPath, splitPath,
takeDirectory)
import Text.Blaze.Html (toHtml)
import Text.Blaze.Html.Renderer.String (renderHtml)
diff --git a/src/Hakyll/Web/Pandoc/Biblio.hs b/src/Hakyll/Web/Pandoc/Biblio.hs
index 9c4b0bf..db022bc 100644
--- a/src/Hakyll/Web/Pandoc/Biblio.hs
+++ b/src/Hakyll/Web/Pandoc/Biblio.hs
@@ -22,12 +22,10 @@ module Hakyll.Web.Pandoc.Biblio
--------------------------------------------------------------------------------
import Control.Applicative ((<$>))
import Data.Binary (Binary (..))
-import Data.Traversable (traverse)
import Data.Typeable (Typeable)
import qualified Text.CSL as CSL
+import Text.CSL.Pandoc (processCites)
import Text.Pandoc (Pandoc, ReaderOptions (..))
-import Text.Pandoc.Biblio (processBiblio)
-
--------------------------------------------------------------------------------
import Hakyll.Core.Compiler
@@ -86,21 +84,20 @@ biblioCompiler = do
--------------------------------------------------------------------------------
readPandocBiblio :: ReaderOptions
- -> Maybe (Item CSL)
+ -> Item CSL
-> Item Biblio
-> (Item String)
-> Compiler (Item Pandoc)
readPandocBiblio ropt csl biblio item = do
-- Parse CSL file, if given
- style <- unsafeCompiler $
- traverse (CSL.readCSLFile . toFilePath . itemIdentifier) csl
+ style <- unsafeCompiler $ CSL.readCSLFile . toFilePath . itemIdentifier $ csl
-- 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 Biblio refs = itemBody biblio
- ropt' = ropt {readerReferences = readerReferences ropt ++ refs}
- pandoc = itemBody $ readPandocWith ropt' item
- pandoc' = processBiblio style refs pandoc
+ pandoc = itemBody $ readPandocWith ropt item
+ pandoc' = processCites style refs pandoc
return $ fmap (const pandoc') item
+
diff --git a/src/Hakyll/Web/Template/Context.hs b/src/Hakyll/Web/Template/Context.hs
index ecf769d..cd52eb0 100644
--- a/src/Hakyll/Web/Template/Context.hs
+++ b/src/Hakyll/Web/Template/Context.hs
@@ -6,6 +6,8 @@ module Hakyll.Web.Template.Context
, field
, constField
, listField
+ , functionField
+ , mapContext
, defaultContext
, bodyField
@@ -86,6 +88,26 @@ listField key c xs = field' key $ \_ -> fmap (ListField c) xs
--------------------------------------------------------------------------------
+functionField :: String -> ([String] -> Item a -> Compiler String) -> Context a
+functionField name value = Context $ \k i -> case words k of
+ [] -> empty
+ (n : args)
+ | n == name -> StringField <$> value args i
+ | otherwise -> empty
+
+
+--------------------------------------------------------------------------------
+mapContext :: (String -> String) -> Context a -> Context a
+mapContext f (Context c) = Context $ \k i -> do
+ fld <- c k i
+ case fld of
+ StringField str -> return $ StringField (f str)
+ ListField _ _ -> fail $
+ "Hakyll.Web.Template.Context.mapContext: " ++
+ "can't map over a ListField!"
+
+
+--------------------------------------------------------------------------------
defaultContext :: Context String
defaultContext =
bodyField "body" `mappend`
@@ -108,7 +130,7 @@ bodyField key = field key $ return . itemBody
--------------------------------------------------------------------------------
-- | Map any field to its metadata value, if present
-metadataField :: Context String
+metadataField :: Context a
metadataField = Context $ \k i -> do
value <- getMetadataField (itemIdentifier i) k
maybe empty (return . StringField) value
@@ -130,7 +152,7 @@ pathField key = field key $ return . toFilePath . itemIdentifier
--------------------------------------------------------------------------------
-- | This title field takes the basename of the underlying file by default
titleField :: String -> Context a
-titleField key = field key $ return . takeBaseName . toFilePath . itemIdentifier
+titleField = mapContext takeBaseName . pathField
--------------------------------------------------------------------------------
diff --git a/src/Hakyll/Web/Template/Read.hs b/src/Hakyll/Web/Template/Read.hs
index bb5c8c2..2421b2d 100644
--- a/src/Hakyll/Web/Template/Read.hs
+++ b/src/Hakyll/Web/Template/Read.hs
@@ -21,7 +21,7 @@ import Hakyll.Web.Template.Internal
readTemplate :: String -> Template
readTemplate input = case parse template "" input of
Left err -> error $ "Cannot parse template: " ++ show err
- Right t -> t
+ Right t -> t
--------------------------------------------------------------------------------