From e914e77f87a51c25141ab297d11344118a6f6e20 Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Tue, 11 Feb 2025 14:47:40 -0600 Subject: Working on aliases --- src/Hakyll/Alias.hs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/Hakyll/Alias.hs') diff --git a/src/Hakyll/Alias.hs b/src/Hakyll/Alias.hs index 598f5e2..4284e3d 100644 --- a/src/Hakyll/Alias.hs +++ b/src/Hakyll/Alias.hs @@ -1,6 +1,8 @@ module Hakyll.Alias ( aliasCtxt , personCtxt + , licenseCtxt + , journalCtxt ) where import Prolog @@ -8,16 +10,22 @@ import Hakyll import Data.Alias import Data.Name import Data.Person +import Data.Journal +import Data.License +import Text.Blaze +import Hakyll.Web.Template.Util (functionField1) -functionField1 :: String -> (String -> Compiler String) -> Context a -functionField1 n f = functionField n $ \case - [x] -> \_ -> f x - _ -> \_ -> fail $ "Expecting exactly one argument to " <> n aliasCtxt :: (Ord a, FromAlias a x) => String -> (String -> Compiler a) -> (x -> Compiler String) -> AliasMap a x -> Context c aliasCtxt name toa fromx amap = functionField1 name $ toa >=> flip resolveAlias amap >=> fromx -personCtxt :: AliasMap Name_ Person_ -> Context a -personCtxt = aliasCtxt "person" (parseName . toSL) (pure . toSL . personHtml) +personCtxt :: (StringConv StrictText s, Ord (Name s), ToMarkup s) => AliasMap (Name s) (Person s) -> Context a +personCtxt = aliasCtxt "person" (fmap (fmap toSL) . parseName . toSL) (pure . toSL . personHtml) + +licenseCtxt :: (StringConv String s, Ord s, ToMarkup s) => AliasMap s (License s) -> Context a +licenseCtxt = aliasCtxt "license" (pure . toSL) (pure . toSL . licenseHtml) + +journalCtxt :: (StringConv String s, Ord s, ToMarkup s) => AliasMap s (Journal s) -> Context a +journalCtxt = aliasCtxt "journal" (pure . toSL) (pure . toSL . journalHtml) -- cgit v1.2.3