Update to new version of Hakyll.

Whew. I need to refactor this.
This commit is contained in:
Justin Hsu 2017-09-20 15:20:50 +01:00
parent 7a2f517346
commit f70e1b7fd2
2 changed files with 7 additions and 4 deletions

View File

@ -18,6 +18,7 @@ import Data.Binary (Binary (..))
import Data.Char (isSpace) import Data.Char (isSpace)
import Data.List.Split (splitOn) import Data.List.Split (splitOn)
import Data.List (intercalate) import Data.List (intercalate)
import Data.Map (empty)
import Data.Typeable (Typeable) import Data.Typeable (Typeable)
import Hakyll import Hakyll
import qualified Bibtex as B import qualified Bibtex as B
@ -38,13 +39,14 @@ instance Binary BibEntry where
get = BibEntry <$> (B.Item <$> get <*> get <*> get) get = BibEntry <$> (B.Item <$> get <*> get <*> get)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- XXX refactor to use Context monoid XXX
bibEntryContext :: Context BibEntry bibEntryContext :: Context BibEntry
bibEntryContext = Context $ \key _ item -> bibEntryContext = Context $ \key _ item ->
let BibEntry t = itemBody item let BibEntry t = itemBody item
in case key of in case key of
"identifier" -> return $ StringField $ B.identifier t "identifier" -> return $ StringField $ B.identifier t
_ -> case lookup key (B.fields t) of _ -> case lookup key (B.fields t) of
Nothing -> empty Nothing -> Control.Applicative.empty
Just val -> case key of Just val -> case key of
"author" -> return $ StringField $ formatAuthors val "author" -> return $ StringField $ formatAuthors val
"month" -> return $ StringField $ expandMonth val "month" -> return $ StringField $ expandMonth val
@ -62,6 +64,7 @@ bibFileEntryNames (BibFile es) = [B.identifier t | BibEntry t <- es]
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- XXX refactor to use Text.CSL.readBiblioFile XXX
parseBibFile :: String -> BibFile parseBibFile :: String -> BibFile
parseBibFile string = case Parsec.runParser (B.bibEntries <* Parsec.eof) parseBibFile string = case Parsec.runParser (B.bibEntries <* Parsec.eof)
[] "<bib file>" string of [] "<bib file>" string of
@ -124,7 +127,8 @@ trimSpace = f . f
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
latexToHtml tex = latexToHtml tex =
let p = case Pandoc.readLaTeX Pandoc.def tex of let p = case Pandoc.readLaTeX Pandoc.def tex of
Pandoc.Pandoc meta [Pandoc.Para para] -> Right (Pandoc.Pandoc meta [Pandoc.Para para]) ->
Pandoc.Pandoc meta [Pandoc.Plain para] Pandoc.Pandoc meta [Pandoc.Plain para]
x -> x Left _ ->
Pandoc.Pandoc (Pandoc.Meta Data.Map.empty) []
in Pandoc.writeHtmlString Pandoc.def p in Pandoc.writeHtmlString Pandoc.def p

View File

@ -6,7 +6,6 @@ import Hakyll
import HakyllBibTex import HakyllBibTex
import System.Process import System.Process
import Text.Pandoc.Options import Text.Pandoc.Options
import Text.Regex
config :: Configuration config :: Configuration
config = defaultConfiguration config = defaultConfiguration