From ed300e0b45bb46adec77b85474544f8908445a14 Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Tue, 25 Feb 2025 12:11:31 -0600 Subject: Writing utils for parsing and formatting my papers --- src/Hakyll/Web/Template/Util.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/Hakyll/Web/Template/Util.hs') diff --git a/src/Hakyll/Web/Template/Util.hs b/src/Hakyll/Web/Template/Util.hs index f08c041..02a46b0 100644 --- a/src/Hakyll/Web/Template/Util.hs +++ b/src/Hakyll/Web/Template/Util.hs @@ -1,6 +1,8 @@ module Hakyll.Web.Template.Util ( functionField1 , slug + , cat + , identifierLink ) where import Prolog @@ -8,6 +10,7 @@ import Hakyll import Hakyll.Web.Template.Context import Data.String.Slugger import System.FilePath +import Witherable functionField1 :: String -> (String -> Compiler String) -> Context a functionField1 n f = functionField n $ \case @@ -16,3 +19,18 @@ functionField1 n f = functionField n $ \case slug :: Context a slug = functionField "slug" $ \strs _ -> pure $ toSlug $ unwords strs + +cat :: Context a +cat = functionField "cat" $ \strs _ -> pure $ concat strs + + +identifierLink :: Context a +identifierLink = functionField1 "identifier" $ \str -> do + getPaths (fromString str) >>= \case + [] -> noResult $ "No filepaths match the pattern " <> str + x@(_:_:_) -> noResult $ "Multiple filepaths match the pattern " <> str <> ": " <> show x + [x] -> pure x + + +getPaths :: Pattern -> Compiler [FilePath] +getPaths = getMatches >=> witherM getRoute -- cgit v1.2.3