summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wells <chris@mathematicaster.org>2025-02-11 14:47:40 -0600
committerChris Wells <chris@mathematicaster.org>2025-02-11 14:47:40 -0600
commite914e77f87a51c25141ab297d11344118a6f6e20 (patch)
tree0aef8b8da0a6ad630834d77a838657b839d791f0
parent0c677070edf9978cb85a0b521f7e6e0ef6d6b491 (diff)
downloadmain-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
-rw-r--r--app/Main.hs26
-rw-r--r--data/papers.bib0
-rw-r--r--src/Data/Alias.hs3
-rw-r--r--src/Hakyll/Alias.hs20
-rw-r--r--src/Hakyll/Web/Template/Util.hs9
-rw-r--r--src/WWW/Base.hs8
6 files changed, 54 insertions, 12 deletions
diff --git a/app/Main.hs b/app/Main.hs
index 632651e..f739cae 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -2,8 +2,32 @@ module Main where
import Prolog
import Hakyll
+
+import Hakyll.Alias
+import Data.Alias (AliasMap)
+import Data.Name (Name_)
+import Data.Person (Person_)
+import Data.Journal (Journal_)
+import Data.License (License_)
+import Hakyll.Aeson (yamlCompiler)
+import Hakyll.TeX.BibTeX (bibtexCompiler)
import WWW.Base (baseHakyll, domain)
+import WWW.Templates (myContext)
+
+
main :: IO ()
main = baseHakyll domain $ do
- undefined
+ match "templates/**" $ compile templateCompiler
+ match "data/*.bib" $ compile bibtexCompiler
+ -- match "data/people.yaml" $ compile $ yamlCompiler @(AliasMap Name_ Person_)
+ -- match "data/licenses.yaml" $ compile $ yamlCompiler @(AliasMap StrictText License_)
+ -- match "data/journals.yaml" $ compile $ yamlCompiler @(AliasMap StrictText Journal_)
+ let baseCtxt :: Compiler (Context String)
+ baseCtxt = fold <$> sequence
+ [ pure myContext
+ , personCtxt @StrictText <$> loadBody "data/people.yaml"
+ , licenseCtxt @StrictText <$> loadBody "data/licenses.yaml"
+ , journalCtxt @StrictText <$> loadBody "data/journals.yaml"
+ ]
+ pure ()
diff --git a/data/papers.bib b/data/papers.bib
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/data/papers.bib
diff --git a/src/Data/Alias.hs b/src/Data/Alias.hs
index 270ce1f..357f901 100644
--- a/src/Data/Alias.hs
+++ b/src/Data/Alias.hs
@@ -94,9 +94,6 @@ instance FromAlias (TrivialAlias a) a where
-- instance FromAlias a a where
-- fromAlias = pure
-instance (FromAlias a x, FromAlias b x) => FromAlias (Either a b) x where
- fromAlias = either fromAlias fromAlias
-
instance FromAlias a x => FromAlias (Aliased a x) x where
fromAlias = either fromAlias pure . unAliased
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
diff --git a/src/WWW/Base.hs b/src/WWW/Base.hs
index ab4f214..0d6a9bf 100644
--- a/src/WWW/Base.hs
+++ b/src/WWW/Base.hs
@@ -1,7 +1,9 @@
+{-# LANGUAGE QuasiQuotes #-}
module WWW.Base
( baseConfig
, baseHakyll
, domain
+ , url
, wwwRoot
, myHakyllReaderOptions
, myHakyllWriterOptions
@@ -11,12 +13,16 @@ import Prolog
import Hakyll
import System.Process
import Text.Pandoc.Options
-
+import Network.URI
+import Network.URI.Static
-- | mathematicaster.org
domain :: IsString s => s
domain = "mathematicaster.org"
+url :: URI
+url = [uri|https://mathematicaster.org/|]
+
-- | /var/www
wwwRoot :: IsString s => s
wwwRoot = "/var/www"