summaryrefslogtreecommitdiff
path: root/src/Hakyll
diff options
context:
space:
mode:
Diffstat (limited to 'src/Hakyll')
-rw-r--r--src/Hakyll/Core/Identifier/Pattorn.hs16
-rw-r--r--src/Hakyll/TeX/BibTeX.hs36
-rw-r--r--src/Hakyll/TeX/HaTeX.hs15
-rw-r--r--src/Hakyll/TeX/LaTeX.hs18
-rw-r--r--src/Hakyll/TeX/TikZ.hs29
5 files changed, 114 insertions, 0 deletions
diff --git a/src/Hakyll/Core/Identifier/Pattorn.hs b/src/Hakyll/Core/Identifier/Pattorn.hs
new file mode 100644
index 0000000..0910320
--- /dev/null
+++ b/src/Hakyll/Core/Identifier/Pattorn.hs
@@ -0,0 +1,16 @@
+module Hakyll.Core.Identifier.Pattorn
+ ( Pattorn (..)
+ ) where
+
+import Prolog
+import Hakyll
+
+-- | Wrapper around 'Pattern' to get a semigroup with "or" as its operation
+newtype Pattorn = Pattorn { getPattern :: Pattern }
+ deriving newtype (Binary, Show, IsString)
+
+instance Semigroup Pattorn where
+ Pattorn a <> Pattorn b = Pattorn $ a .||. b
+
+instance Monoid Pattorn where
+ mempty = Pattorn $ complement mempty
diff --git a/src/Hakyll/TeX/BibTeX.hs b/src/Hakyll/TeX/BibTeX.hs
new file mode 100644
index 0000000..b085dfa
--- /dev/null
+++ b/src/Hakyll/TeX/BibTeX.hs
@@ -0,0 +1,36 @@
+{-# OPTIONS_GHC -fno-warn-orphans #-}
+module Hakyll.TeX.BibTeX
+ ( bibtexCompiler
+ , compileBibtex
+ , BibTeX
+ ) where
+
+import Prolog
+
+import Data.List qualified as L
+import Hakyll
+import Text.BibTeX.Entry qualified as B
+import Text.BibTeX.Format qualified as B
+import Text.BibTeX.Parse qualified as B
+import Text.Parsec qualified as P
+import Text.Parsec.Error qualified as P
+
+type BibTeX = B.T
+
+deriving instance Generic B.T
+instance Binary B.T
+
+instance Writable B.T where
+ write p = write p . B.entry
+
+instance Writable [B.T] where
+ write p = write p . fold . L.intersperse "\n" . fmap B.entry
+
+
+compileBibtex :: (StringConv s String) => Item s -> Compiler (Item [B.T])
+compileBibtex (Item i b) = either (throwError . fmap P.messageString . P.errorMessages) (pure . Item i) $ P.parse p (show i) (toSL b)
+ where
+ p = B.skippingLeadingSpace $ B.file <* P.eof
+
+bibtexCompiler :: Compiler (Item [B.T])
+bibtexCompiler = getResourceBody >>= compileBibtex
diff --git a/src/Hakyll/TeX/HaTeX.hs b/src/Hakyll/TeX/HaTeX.hs
new file mode 100644
index 0000000..9b83c62
--- /dev/null
+++ b/src/Hakyll/TeX/HaTeX.hs
@@ -0,0 +1,15 @@
+module Hakyll.TeX.HaTeX
+ ( hatexCompiler
+ , compileHatex
+ ) where
+
+import Prolog
+
+import Hakyll
+import Text.LaTeX.Base.Parser
+
+compileHatex :: (StringConv s Text, Traversable t) => t s -> Compiler (t LaTeX)
+compileHatex = traverse $ either (throwError . fmap messageString . errorMessages) pure . parseLaTeX . toSL
+
+hatexCompiler :: Compiler (Item LaTeX)
+hatexCompiler = getResourceLBS >>= compileHatex
diff --git a/src/Hakyll/TeX/LaTeX.hs b/src/Hakyll/TeX/LaTeX.hs
new file mode 100644
index 0000000..8f6d5cc
--- /dev/null
+++ b/src/Hakyll/TeX/LaTeX.hs
@@ -0,0 +1,18 @@
+module Hakyll.TeX.LaTeX
+ ( latexPdfCompiler
+ , compileLatexPdf
+ , rubberPipe
+ ) where
+
+import Prolog
+
+import Hakyll
+
+rubberPipe :: [String] -> LazyByteString -> Compiler LazyByteString
+rubberPipe = unixFilterLBS "rubber-pipe"
+
+compileLatexPdf :: (StringConv s LazyByteString, Traversable t) => t s -> Compiler (t LazyByteString)
+compileLatexPdf = traverse $ rubberPipe [ "--pdf" ] . toSL
+
+latexPdfCompiler :: Compiler (Item LazyByteString)
+latexPdfCompiler = getResourceLBS >>= compileLatexPdf
diff --git a/src/Hakyll/TeX/TikZ.hs b/src/Hakyll/TeX/TikZ.hs
new file mode 100644
index 0000000..9df98fd
--- /dev/null
+++ b/src/Hakyll/TeX/TikZ.hs
@@ -0,0 +1,29 @@
+module Hakyll.TeX.TikZ
+ ( TikzTemplate
+ , tikzfilter
+ , tikzBlockFilter
+ ) where
+
+import Network.URI.Encode qualified as URI
+import Text.Pandoc.Definition
+import Text.Pandoc.Walk (walkM)
+
+import Hakyll
+
+import Prolog
+
+import Hakyll.TeX.LaTeX (rubberPipe)
+
+type TikzTemplate = Identifier
+
+tikzFilter :: TikzTemplate -> Pandoc -> Compiler Pandoc
+tikzFilter = walkM tikzBlockFilter
+
+-- | Requires `rubber` and `poppler_utils`
+tikzBlockFilter :: TikzTemplate -> Block -> Compiler Block
+tikzBlockFilter tmpl (CodeBlock info@(_, "tikzpicture":_, _) contents) = do
+ let imageBlock fname = Para [ Image info [] (toSL fname, "") ]
+ makeItem (toSL contents) >>= loadAndApplyTemplate tmpl (bodyField "body") >>=
+ traverse (convSL $ rubberPipe [ "--pdf" ] >=> unixFilterLBS "pdftocairo" [ "-svg", "-", "-" ]) >>=
+ \(Item _ b) -> imageBlock $ ("data:image/svg+sml;utf8," <>) $ URI.encode $ filter (/= '\n') b
+tikzBlockFilter _ x = pure x