summaryrefslogtreecommitdiff
path: root/src/Hakyll/Web/Template
diff options
context:
space:
mode:
Diffstat (limited to 'src/Hakyll/Web/Template')
-rw-r--r--src/Hakyll/Web/Template/Util.hs18
1 files changed, 18 insertions, 0 deletions
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