summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--flake.nix1
-rw-r--r--package.yaml2
-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
-rw-r--r--templates/default.html56
-rw-r--r--templates/math.html4
-rw-r--r--templates/nav.html9
-rw-r--r--templates/tikz.tex13
-rw-r--r--www-main.cabal8
16 files changed, 197 insertions, 29 deletions
diff --git a/flake.nix b/flake.nix
index af28c99..faee116 100644
--- a/flake.nix
+++ b/flake.nix
@@ -29,6 +29,7 @@
cabal-install
hpack
pkgs.zlib
+ pkgs.icu
];
};
});
diff --git a/package.yaml b/package.yaml
index 776920e..8eee7f6 100644
--- a/package.yaml
+++ b/package.yaml
@@ -43,12 +43,14 @@ library:
- blaze-html
- bytestring
- email-validate
+ - exceptions
- filepath
- hakyll
- HaTeX
- mtl
- network-uri
- pandoc
+ - pandoc-types
- parsec
- process
- slugger
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
+ ]
diff --git a/templates/default.html b/templates/default.html
new file mode 100644
index 0000000..124a2f2
--- /dev/null
+++ b/templates/default.html
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML>
+<html lang="en" color-mode="light">
+ <head>
+ <title>$title$</title>
+ $if(author)$
+ <meta name="author" content="$author$">
+ $else$
+ <meta name="author" content="Chris Wells">
+ $endif$
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
+ <meta name="viewport" content="width=device-width, initial-scale=1" >
+
+ <link rel="stylesheet" href="/css/main.css">
+ <link rel="stylesheet" href="/css/fontawesome.css">
+ <script type="text/javascript" src="/js/colors.js"></script>
+ $if(toggle)$
+ <script type="text/javascript" src="/js/toggle.js"></script>
+ $endif$
+ $if(math)$
+ $partial("templates/math.html")$
+ $endif$
+ <!-- <script src="https://kit.fontawesome.com/cd6957df2d.js" crossorigin="anonymous"></script> -->
+
+ <!-- favicons -->
+ <link rel="shortcut icon" href="/favicon.ico">
+ <link rel="icon" sizes="16x16 32x32 64x64" href="/favicon.ico">
+ <link rel="icon" type="image/png" sizes="196x196" href="/img/favicon/favicon-192.png">
+ <link rel="icon" type="image/png" sizes="160x160" href="/img/favicon/favicon-160.png">
+ <link rel="icon" type="image/png" sizes="96x96" href="/img/favicon/favicon-96.png">
+ <link rel="icon" type="image/png" sizes="64x64" href="/img/favicon/favicon-64.png">
+ <link rel="icon" type="image/png" sizes="32x32" href="/img/favicon/favicon-32.png">
+ <link rel="icon" type="image/png" sizes="16x16" href="/img/favicon/favicon-16.png">
+
+ </head>
+ <body>
+ <header>
+ $partial("templates/nav.html")$
+ </header>
+
+ <div id="main">
+ $body$
+ </div>
+
+ <footer>
+ <hr />
+ <div class="pull-left">
+ <button class="toggle-color-button" onclick='toggleColorMode()'><i class="fas fa-adjust"></i></button>
+
+ <a href="/credits.html"><i class="fas fa-info-circle"></i></a>
+ </div>
+ <div class="pull-right">
+ <a href="mailto:$workEmail$"><i class="fa fa-envelope"></i> $workEmail$</a>
+ </div>
+ </footer>
+ </body>
+</html>
diff --git a/templates/math.html b/templates/math.html
new file mode 100644
index 0000000..00ed73f
--- /dev/null
+++ b/templates/math.html
@@ -0,0 +1,4 @@
+<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css" integrity="sha384-zB1R0rpPzHqg7Kpt0Aljp8JPLqbXI3bhnPWROx27a9N0Ll6ZP/+DiW/UqRcLbRjq" crossorigin="anonymous">
+<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js" integrity="sha384-y23I5Q6l+B6vatafAwxRu/0oK/79VlbSz7Q9aiSZUvyWYIYsd+qj+o24G5ZU2zJz" crossorigin="anonymous"></script>
+<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/auto-render.min.js" integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI" crossorigin="anonymous"></script>
+<script type="text/javascript" src="/js/katex.js"></script>
diff --git a/templates/nav.html b/templates/nav.html
new file mode 100644
index 0000000..077fd1e
--- /dev/null
+++ b/templates/nav.html
@@ -0,0 +1,9 @@
+<div id="menu">
+ <a href="/"><i class="fa fa-home"></i> Chris Wells</a>
+ <span class="pull-right">
+ <a href="/research"><i class="fa fa-book"></i> Research</a>
+ <a href="/teaching"><i class="fa fa-chalkboard-teacher"></i> Teaching</a>
+ <a href="/contact.html"><i class="fa fa-address-book"></i> Contact</a>
+ <a href="/doc/cv.pdf"><i class="fa fa-file-alt"></i> CV</a>
+ </span>
+</div>
diff --git a/templates/tikz.tex b/templates/tikz.tex
new file mode 100644
index 0000000..b091d9b
--- /dev/null
+++ b/templates/tikz.tex
@@ -0,0 +1,13 @@
+\documentclass{article}
+\usepackage[pdftex,active,tightpage]{preview}
+\usepackage{amsmath}
+\usepackage{tikz}
+\usetikzlibrary{matrix}
+
+\begin{document}
+\begin{preview}
+ \begin{tikzpicture}[auto]
+ $body$
+ \end{tikzpicture}
+\end{preview}
+\end{document}
diff --git a/www-main.cabal b/www-main.cabal
index 4f84d0a..adbb3f5 100644
--- a/www-main.cabal
+++ b/www-main.cabal
@@ -16,14 +16,17 @@ library
exposed-modules:
Hakyll.Core.Identifier.Pattorn
Hakyll.Error
- Hakyll.Parsec.Parsec
+ Hakyll.Parsec
Hakyll.TeX.BibTeX
Hakyll.TeX.HaTeX
Hakyll.TeX.LaTeX
Hakyll.TeX.TikZ
+ Hakyll.Util
+ Hakyll.Web.Template.Util
Prolog
WWW.Base
WWW.HW
+ WWW.Templates
other-modules:
Paths_www_main
hs-source-dirs:
@@ -51,13 +54,16 @@ library
, bytestring
, comonad
, email-validate
+ , exceptions
, filepath
, hakyll
, mtl
, network-uri
, pandoc
+ , pandoc-types
, parsec
, process
+ , slugger
, string-conv
, text
, uri-encode