summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChris Wells <chris@mathematicaster.org>2025-01-25 14:33:21 -0600
committerChris Wells <chris@mathematicaster.org>2025-01-25 14:33:21 -0600
commitca1d4d3d4371c8175ea6addb1ca1b09c3b56a7bb (patch)
treebabd478f4191655b2fa26f584c872fb909363ef1 /src
parent39d9569a2561f8ea09170b4371deca130c1ebcf9 (diff)
downloadmain-ca1d4d3d4371c8175ea6addb1ca1b09c3b56a7bb.tar
main-ca1d4d3d4371c8175ea6addb1ca1b09c3b56a7bb.tar.gz
main-ca1d4d3d4371c8175ea6addb1ca1b09c3b56a7bb.tar.bz2
main-ca1d4d3d4371c8175ea6addb1ca1b09c3b56a7bb.tar.lz
main-ca1d4d3d4371c8175ea6addb1ca1b09c3b56a7bb.tar.xz
main-ca1d4d3d4371c8175ea6addb1ca1b09c3b56a7bb.tar.zst
main-ca1d4d3d4371c8175ea6addb1ca1b09c3b56a7bb.zip
Adding templates and cleaning up
Diffstat (limited to 'src')
-rw-r--r--src/Hakyll/Error.hs16
-rw-r--r--src/Hakyll/Parsec.hs (renamed from src/Hakyll/Parsec/Parsec.hs)2
-rw-r--r--src/Hakyll/TeX/BibTeX.hs16
-rw-r--r--src/Hakyll/TeX/HaTeX.hs3
-rw-r--r--src/Hakyll/TeX/TikZ.hs25
-rw-r--r--src/Hakyll/Util.hs19
-rw-r--r--src/Prolog.hs16
-rw-r--r--src/WWW/Base.hs3
-rw-r--r--src/WWW/Templates.hs33
9 files changed, 105 insertions, 28 deletions
diff --git a/src/Hakyll/Error.hs b/src/Hakyll/Error.hs
index 35102d4..7495b4d 100644
--- a/src/Hakyll/Error.hs
+++ b/src/Hakyll/Error.hs
@@ -14,17 +14,17 @@ class ErrorConv c err where
type CompilerError c = ErrorConv c [String]
-instance ErrorCnv err err where
+instance ErrorConv err err where
toErr = id
-instance Exception c => ErrorCnv c SomeException where
+instance Exception c => ErrorConv c SomeException where
toErr = SomeException
--- instance Functor f => ErrorCnv c err => ErrorCnv (f c) (f err) where
+-- instance Functor f => ErrorConv c err => ErrorConv (f c) (f err) where
-- toErr = fmap toErr
-instance (Applicative f, ErrorCnv c err) => ErrorCnv c (f err) where
- toErr = pure . toErr
+-- instance (Applicative f, ErrorConv c err) => ErrorConv c (f err) where
+-- toErr = pure . toErr
throwErr :: (MonadError err m, ErrorConv c err) => c -> m a
throwErr = throwError . toErr
@@ -38,6 +38,12 @@ squashErr = (>>= liftErr)
instance ErrorConv Message String where
toErr = messageString
+instance ErrorConv String [String] where
+ toErr = pure
+
+instance ErrorConv Message [String] where
+ toErr = pure . messageString
+
instance ErrorConv ParseError [String] where
toErr = fmap messageString . errorMessages
diff --git a/src/Hakyll/Parsec/Parsec.hs b/src/Hakyll/Parsec.hs
index 123c5fd..edd7b18 100644
--- a/src/Hakyll/Parsec/Parsec.hs
+++ b/src/Hakyll/Parsec.hs
@@ -1,4 +1,4 @@
-module Hakyll.Parsec.Parsec
+module Hakyll.Parsec
( compileParsec
, compileParsec_
, parsecCompiler
diff --git a/src/Hakyll/TeX/BibTeX.hs b/src/Hakyll/TeX/BibTeX.hs
index 434ca54..ddf9166 100644
--- a/src/Hakyll/TeX/BibTeX.hs
+++ b/src/Hakyll/TeX/BibTeX.hs
@@ -2,6 +2,7 @@
module Hakyll.TeX.BibTeX
( bibtexCompiler
, compileBibtex
+ , BibEntry
, BibTeX
) where
@@ -10,28 +11,29 @@ 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.Format qualified as BF
import Text.BibTeX.Parse qualified as B
import Text.Parsec qualified as P
-import Hakyll.Parsec.Parsec
+import Hakyll.Parsec
-type BibTeX = B.T
+type BibEntry = B.T
+type BibTeX = [BibEntry]
deriving instance Generic B.T
instance Binary B.T
instance Writable B.T where
- write p = write p . B.entry
+ write p = write p . fmap BF.entry
instance Writable [B.T] where
- write p = write p . fold . L.intersperse "\n" . fmap B.entry
+ write p = write p . fmap (fold . L.intersperse "\n" . fmap BF.entry)
-compileBibtex :: (StringConv s String) => Item s -> Compiler (Item [B.T])
+compileBibtex :: (StringConv s String) => Item s -> Compiler (Item BibTeX)
compileBibtex = compileParsec_ p . fmap toSL
where
p = B.skippingLeadingSpace $ B.file <* P.eof
-bibtexCompiler :: Compiler (Item [B.T])
+bibtexCompiler :: Compiler (Item BibTeX)
bibtexCompiler = getResourceBody >>= compileBibtex
diff --git a/src/Hakyll/TeX/HaTeX.hs b/src/Hakyll/TeX/HaTeX.hs
index c71ad09..790d57c 100644
--- a/src/Hakyll/TeX/HaTeX.hs
+++ b/src/Hakyll/TeX/HaTeX.hs
@@ -8,9 +8,10 @@ import Prolog
import Hakyll
import Hakyll.Error
-- import Hakyll.Parsec.Parsec
+import Text.LaTeX.Base
import Text.LaTeX.Base.Parser
-compileHatex :: (StringConv s Text, Traversable t, MonadError [String] m) => t s -> m (t LaTeX)
+compileHatex :: (StringConv s StrictText, Traversable t, MonadError [String] m) => t s -> m (t LaTeX)
compileHatex = traverse $ liftErr . parseLaTeX . toSL
hatexCompiler :: Compiler (Item LaTeX)
diff --git a/src/Hakyll/TeX/TikZ.hs b/src/Hakyll/TeX/TikZ.hs
index 9df98fd..c9087e7 100644
--- a/src/Hakyll/TeX/TikZ.hs
+++ b/src/Hakyll/TeX/TikZ.hs
@@ -1,7 +1,12 @@
+{-# LANGUAGE TemplateHaskell #-}
module Hakyll.TeX.TikZ
( TikzTemplate
- , tikzfilter
+ , tikzFilter
, tikzBlockFilter
+ -- * Using the default TikZ template
+ , tikzTemplate
+ , tikzFilter_
+ , tikzBlockFilter_
) where
import Network.URI.Encode qualified as URI
@@ -14,16 +19,26 @@ import Prolog
import Hakyll.TeX.LaTeX (rubberPipe)
-type TikzTemplate = Identifier
+type TikzTemplate = Template
tikzFilter :: TikzTemplate -> Pandoc -> Compiler Pandoc
-tikzFilter = walkM tikzBlockFilter
+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") >>=
+ makeItem (toSL contents) >>= applyTemplate tmpl (bodyField "body") >>=
traverse (convSL $ rubberPipe [ "--pdf" ] >=> unixFilterLBS "pdftocairo" [ "-svg", "-", "-" ]) >>=
- \(Item _ b) -> imageBlock $ ("data:image/svg+sml;utf8," <>) $ URI.encode $ filter (/= '\n') b
+ \(Item _ b) -> pure $ imageBlock $ ("data:image/svg+sml;utf8," <>) $ URI.encode $ filter (/= '\n') b
tikzBlockFilter _ x = pure x
+
+
+tikzTemplate :: TikzTemplate
+tikzTemplate = $(embedTemplate "templates/tikz.tex")
+
+tikzBlockFilter_ :: Block -> Compiler Block
+tikzBlockFilter_ = tikzBlockFilter tikzTemplate
+
+tikzFilter_ :: Pandoc -> Compiler Pandoc
+tikzFilter_ = tikzFilter tikzTemplate
diff --git a/src/Hakyll/Util.hs b/src/Hakyll/Util.hs
new file mode 100644
index 0000000..edbdb16
--- /dev/null
+++ b/src/Hakyll/Util.hs
@@ -0,0 +1,19 @@
+module Hakyll.Util
+ ( dropParentRoute
+ , modifyDirRoute
+ , modifyDirRoute_
+ ) where
+
+import Prolog
+import Hakyll
+import System.FilePath
+
+-- | Drop some number of parent directories
+dropParentRoute :: Int -> Routes
+dropParentRoute n = modifyDirRoute_ $ drop n
+
+modifyDirRoute :: ([FilePath] -> FilePath) -> Routes
+modifyDirRoute f = customRoute $ f . splitDirectories . toFilePath
+
+modifyDirRoute_ :: ([FilePath] -> [FilePath]) -> Routes
+modifyDirRoute_ f = modifyDirRoute $ joinPath . f
diff --git a/src/Prolog.hs b/src/Prolog.hs
index a688063..4b3c666 100644
--- a/src/Prolog.hs
+++ b/src/Prolog.hs
@@ -27,8 +27,8 @@ module Prolog
, SomeException (..)
, B.StrictByteString
, BL.LazyByteString
- , T.StrictText
- , TL.LazyText
+ , StrictText
+ , LazyText
-- * Strings
, IsString (..)
, StringConv (..)
@@ -83,6 +83,10 @@ import Text.Blaze.Html.Renderer.Pretty as BS
import Text.Blaze.Html.Renderer.Text as BT
import Text.Blaze.Html.Renderer.Utf8 as BB
import Text.LaTeX.Base qualified as L
+import Text.LaTeX.Base.Syntax qualified as L
+
+type StrictText = T.Text
+type LazyText = TL.Text
(<<$>>) :: (Functor f, Functor g) => (a -> b) -> f (g a) -> f (g b)
infixl 4 <<$>>
@@ -124,8 +128,8 @@ liftMaybe :: Alternative m => Maybe a -> m a
liftMaybe = maybe empty pure
{-# INLINE liftMaybe #-}
-squashMaybe :: Alternative m => m (Maybe a) -> m a
-squashmaybe = (>>= liftMaybe)
+squashMaybe :: (Alternative m, Monad m) => m (Maybe a) -> m a
+squashMaybe = (>>= liftMaybe)
{-# INLINE squashMaybe #-}
renderTo :: (StringConv T.Text s, L.Render r) => r -> s
@@ -171,10 +175,10 @@ instance StringConv L.LaTeX String where
strConv l = strConv l . L.render
instance StringConv Html T.Text where
- strConv _ = BT.renderHtml
+ strConv l = strConv l . BT.renderHtml
instance StringConv Html TL.Text where
- strConv l = strConv l . BT.renderHtml
+ strConv _ = BT.renderHtml
instance StringConv Html String where
strConv _ = BS.renderHtml
diff --git a/src/WWW/Base.hs b/src/WWW/Base.hs
index 4f8d1c7..7c752da 100644
--- a/src/WWW/Base.hs
+++ b/src/WWW/Base.hs
@@ -10,9 +10,6 @@ import Hakyll
import System.Process
-hakyllVersion :: IsString s => s
-hakyllVersion = "Hakyll 4.16.2.2"
-
-- | mathematicaster.org
domain :: IsString s => s
domain = "mathematicaster.org"
diff --git a/src/WWW/Templates.hs b/src/WWW/Templates.hs
new file mode 100644
index 0000000..0068a07
--- /dev/null
+++ b/src/WWW/Templates.hs
@@ -0,0 +1,33 @@
+{-# LANGUAGE TemplateHaskell #-}
+module WWW.Templates
+ ( defaultTemplate
+ , navigationTemplate
+ , mathTemplate
+ , tikzTemplate
+ -- * Context
+ , myContext
+ ) where
+
+import Prolog
+
+import Hakyll
+
+import Hakyll.TeX.TikZ (tikzTemplate)
+
+
+defaultTemplate :: Template
+defaultTemplate = $(embedTemplate "templates/default.html")
+
+navigationTemplate :: Template
+navigationTemplate = $(embedTemplate "templates/nav.html")
+
+mathTemplate :: Template
+mathTemplate = $(embedTemplate "templates/math.html")
+
+
+myContext :: Context String
+myContext = fold
+ [ constField "personalEmail" "chris@mathematicaster.org"
+ , constField "workEmail" "coc0014@auburn.edu"
+ , defaultContext
+ ]