diff options
| author | Chris Wells <chris@mathematicaster.org> | 2025-02-11 14:47:40 -0600 |
|---|---|---|
| committer | Chris Wells <chris@mathematicaster.org> | 2025-02-11 14:47:40 -0600 |
| commit | e914e77f87a51c25141ab297d11344118a6f6e20 (patch) | |
| tree | 0aef8b8da0a6ad630834d77a838657b839d791f0 /src/Hakyll | |
| parent | 0c677070edf9978cb85a0b521f7e6e0ef6d6b491 (diff) | |
| download | main-e914e77f87a51c25141ab297d11344118a6f6e20.tar main-e914e77f87a51c25141ab297d11344118a6f6e20.tar.gz main-e914e77f87a51c25141ab297d11344118a6f6e20.tar.bz2 main-e914e77f87a51c25141ab297d11344118a6f6e20.tar.lz main-e914e77f87a51c25141ab297d11344118a6f6e20.tar.xz main-e914e77f87a51c25141ab297d11344118a6f6e20.tar.zst main-e914e77f87a51c25141ab297d11344118a6f6e20.zip | |
Working on aliases
Diffstat (limited to 'src/Hakyll')
| -rw-r--r-- | src/Hakyll/Alias.hs | 20 | ||||
| -rw-r--r-- | src/Hakyll/Web/Template/Util.hs | 9 |
2 files changed, 22 insertions, 7 deletions
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) diff --git a/src/Hakyll/Web/Template/Util.hs b/src/Hakyll/Web/Template/Util.hs index cfd8573..f08c041 100644 --- a/src/Hakyll/Web/Template/Util.hs +++ b/src/Hakyll/Web/Template/Util.hs @@ -1,11 +1,18 @@ module Hakyll.Web.Template.Util - ( slug + ( functionField1 + , slug ) where import Prolog +import Hakyll import Hakyll.Web.Template.Context import Data.String.Slugger +import System.FilePath +functionField1 :: String -> (String -> Compiler String) -> Context a +functionField1 n f = functionField n $ \case + [x] -> \_ -> f x + xs -> \_ -> fail $ "Expecting exactly one argument to " <> n <> ". Instead got " <> show (length xs) slug :: Context a slug = functionField "slug" $ \strs _ -> pure $ toSlug $ unwords strs |
