From dae3dca29075d5de8c4c51b3eab9bf0334866c9a Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Tue, 14 Jan 2025 11:48:09 -0600 Subject: Adding new modules --- src/Hakyll/Core/Identifier/Pattorn.hs | 2 ++ src/Hakyll/Error.hs | 7 ++++++- src/Hakyll/Parsec/Parsec.hs | 9 ++++++++- src/Hakyll/Web/Template/Util.hs | 11 +++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/Hakyll/Web/Template/Util.hs (limited to 'src') diff --git a/src/Hakyll/Core/Identifier/Pattorn.hs b/src/Hakyll/Core/Identifier/Pattorn.hs index 0910320..e1767c4 100644 --- a/src/Hakyll/Core/Identifier/Pattorn.hs +++ b/src/Hakyll/Core/Identifier/Pattorn.hs @@ -11,6 +11,8 @@ newtype Pattorn = Pattorn { getPattern :: Pattern } instance Semigroup Pattorn where Pattorn a <> Pattorn b = Pattorn $ a .||. b + {-# INLINE (<>) #-} instance Monoid Pattorn where mempty = Pattorn $ complement mempty + {-# INLINE mempty #-} diff --git a/src/Hakyll/Error.hs b/src/Hakyll/Error.hs index 3ca29d3..35102d4 100644 --- a/src/Hakyll/Error.hs +++ b/src/Hakyll/Error.hs @@ -1,6 +1,8 @@ module Hakyll.Error ( ErrorConv (..) , throwErr + , liftErr + , squashErr , CompilerError ) where @@ -15,10 +17,13 @@ type CompilerError c = ErrorConv c [String] instance ErrorCnv err err where toErr = id +instance Exception c => ErrorCnv c SomeException where + toErr = SomeException + -- instance Functor f => ErrorCnv c err => ErrorCnv (f c) (f err) where -- toErr = fmap toErr -instance Applicative f => ErrorCnv c err => ErrorCnv c (f err) where +instance (Applicative f, ErrorCnv c err) => ErrorCnv c (f err) where toErr = pure . toErr throwErr :: (MonadError err m, ErrorConv c err) => c -> m a diff --git a/src/Hakyll/Parsec/Parsec.hs b/src/Hakyll/Parsec/Parsec.hs index cac653c..123c5fd 100644 --- a/src/Hakyll/Parsec/Parsec.hs +++ b/src/Hakyll/Parsec/Parsec.hs @@ -1,7 +1,8 @@ module Hakyll.Parsec.Parsec ( compileParsec , compileParsec_ - , evalParsec + , parsecCompiler + , parsecCompiler_ ) where import Prolog @@ -18,3 +19,9 @@ compileParsec p u itm@(Item i _) = traverse (liftErr . runParser p u (show i)) i compileParsec_ :: (MonadError [String] m, Stream s Identity t) => Parsec s () a -> Item s -> m (Item a) compileParsec_ p = compileParsec p () + +parsecCompiler :: (Stream s Identity t, StringConv LazyByteString s) => Parsec s u a -> u -> Compiler (Item a) +parsecCompiler p u = getResourceLBS >>= compileParsec p u . fmap toSL + +parsecCompiler_ :: (Stream s Identity t, StringConv LazyByteString s) => Parsec s () a -> Compiler (Item a) +parsecCompiler_ p = parsecCompiler p () diff --git a/src/Hakyll/Web/Template/Util.hs b/src/Hakyll/Web/Template/Util.hs new file mode 100644 index 0000000..cfd8573 --- /dev/null +++ b/src/Hakyll/Web/Template/Util.hs @@ -0,0 +1,11 @@ +module Hakyll.Web.Template.Util + ( slug + ) where + +import Prolog +import Hakyll.Web.Template.Context +import Data.String.Slugger + + +slug :: Context a +slug = functionField "slug" $ \strs _ -> pure $ toSlug $ unwords strs -- cgit v1.2.3