summaryrefslogtreecommitdiff
path: root/src/Hakyll/Web/Template/Util.hs
diff options
context:
space:
mode:
authorChris Wells <chris@mathematicaster.org>2025-02-25 12:11:31 -0600
committerChris Wells <chris@mathematicaster.org>2025-02-25 12:11:31 -0600
commited300e0b45bb46adec77b85474544f8908445a14 (patch)
tree70ba794888475baafd2f433a075aa18193fdf03e /src/Hakyll/Web/Template/Util.hs
parente914e77f87a51c25141ab297d11344118a6f6e20 (diff)
downloadmain-ed300e0b45bb46adec77b85474544f8908445a14.tar
main-ed300e0b45bb46adec77b85474544f8908445a14.tar.gz
main-ed300e0b45bb46adec77b85474544f8908445a14.tar.bz2
main-ed300e0b45bb46adec77b85474544f8908445a14.tar.lz
main-ed300e0b45bb46adec77b85474544f8908445a14.tar.xz
main-ed300e0b45bb46adec77b85474544f8908445a14.tar.zst
main-ed300e0b45bb46adec77b85474544f8908445a14.zip
Writing utils for parsing and formatting my papers
Diffstat (limited to 'src/Hakyll/Web/Template/Util.hs')
-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