From e914e77f87a51c25141ab297d11344118a6f6e20 Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Tue, 11 Feb 2025 14:47:40 -0600 Subject: Working on aliases --- app/Main.hs | 26 +++++++++++++++++++++++++- data/papers.bib | 0 src/Data/Alias.hs | 3 --- src/Hakyll/Alias.hs | 20 ++++++++++++++------ src/Hakyll/Web/Template/Util.hs | 9 ++++++++- src/WWW/Base.hs | 8 +++++++- 6 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 data/papers.bib 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 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" -- cgit v1.2.3